How can i add sample data to an edmx file and display it in Visual-Studio - visual-studio-2010

I am using Visual Studio 2010 and ADO.Net Entity Data Model to create my database schema. Since i am still drafting and discussing the schema i would like to be able to add example data to the edmx-file and be able to show it in the designer like in the following screenshot:
Source code of EDMX file with added sample data
The underlying xml-code would contain the normal edmx-output and on top the sample data like below:
<?xml version="1.0" encoding="utf-8"?>
....
<EntityType Name="Title">
<Documentation>
<Summary>Table titles contains all the dvd-title we have in our store</Summary>
</Documentation>
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Type="Int32"
Name="Id" Nullable="false"
annotation:StoreGeneratedPattern="Identity" />
<Property Type="String" Name="Title" Nullable="false" >
<Documentation>
<Summary>The title of the movie</Summary>
<LongDescription>
The translated title of the movie and the original title
</LongDescription>
</Documentation>
</Property>
</EntityType>
<Titles>
<Title>
<id>810</id>
<title>Pulp Fiction</title>
<year>1994</year>
</Title>
<Title>
<id>940</id>
<title>Lock, Stock and Two Smoking Barrels</title>
<year>1998</year>
</Title>
</Titles>
The sample data should be displayed and should be editable in design view.
Does anyone know a tool or a way to combine the edmx-file and to display and add sample data?
Bonus Question: When i generate the sql-statement the documentation is not added to the sql statement. Is there a way to include the documentation of the fields and the tables so that they would be added to Microsoft SQL Server?

I don't think it is possible. One of the reasons is that what you see is a model and not the database schema. What you don't see is how entity is mapped to the database. In the basic scenario there is 1:1 mapping indeed but once you start customizing your model you may end up having columns in the database with names different from the property names in the model, you may have complex properties you would not even have corresponding properties for on the diagram, you may put multiple entities to one table or one entity to multiple tables. How are you going to show this? And since it is just entity model and not table model data does not seem to be a good fit. I don't know of any tool that could do what you need. Edmx is an Xml file and the designer itself is extensible and based on DSL. You can try cooking something yourself but it will be a lot of work.

Related

Retrieve the fetchxml in grid via javascript

This might seem a bit of an odd request so I'll try to offer some background. I have a feature on my CRM which requires that user should be able to filter a view and then save the resulting records such that a separate process can pick them up and process them periodically e.g. daily.
Now here's the catch, they want this process to requery the data before it processes it, so basically what should be saved is the query or filters rather than the data in the view.
Having previously written some javascript code which dynamically sets the fetchxml on a subgrid like so
Subgrid.getGrid().setParameter("fetchXml", fetchxml);
I though it should be fairly straight forward to potentially retrieve the fetchxml in the grid
Subgrid.getGrid().getParameter("fetchXml");
However that doesn't work and I can't seem to find any documentation or anything that can point me in the right direction. I have used Developer tools to inspect the properties of Mscrm.XrmControlGridWrapper but I can't find anything useful..
If anyone knows how I can retrieve the fetchxml that powers a subgrid using javascript, it would be massively helpful?
EDIT
I have just found that I can do this
Subgrid.getGrid().getFilter().$3_1.GetParameter("fetchXml")
and that returns exactly what I want, however this just screams of hacky and unsupported.
$3_1 has a type of [object (Mscrm.TurboGridControl)]
Is there a way I can access this object in a supported way?
A few thoughts on this:
You can retrieve the SystemForm record, then parse the FormXml to get the ViewId. Then you can retrieve the view from the SavedQuery entity, and get the FetchXML. Here's an example of the ViewId in the FormXml:
You could add a boolean field to the entity and when the user saves the set they want to process you can flag those records for the later batch process to retrieve.
When the user identifies the set they want to process you could temporarily create a view (SystemQuery or UserQuery) with the the FetchXML using the "in" operator with the list of Guid's to identify the exact records to process. After using the view to retrieve and process the records, the batch process could delete the view. I would probably be comfortable using this approach up to a few dozen records.
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="account">
<filter type="and">
<condition attribute="accountid" operator="in">
<value>{A1CC84F2-BE0D-E711-8104-00155D6FD705}</value>
<value>{A3CC84F2-BE0D-E711-8104-00155D6FD705}</value>
<value>{A5CC84F2-BE0D-E711-8104-00155D6FD705}</value>
</condition>
</filter>
</entity>
</fetch>
If you want to avoid changing the Modified information by setting a boolean flag on the records to be processed, you could create an N:N linking entity and associate the selected records to an instance of that entity.
You can do:
Since you have the fetchxml that previously set as filter for SubGrid, why don't you store this variable directly. You can save this variable in localStorage or maybe even in a dummy field created for this purpose. And use it in the desired process.
Btw, the supported way of getting fetchXml: Xrm.Page.getControl(gridControlName).getFetchXml()
Hope this helps...

SSAS 2008 R2: How to create dataset fields manually

So, this is a follow up question to this one i made before.
Basically, i wanted to go from
to
which i got.
My final problem is that i dont seem to be able to create a name for these fields for the datasets in ssas.
I tried:
FIELD NAME=CLOSED, FIELD SOURCE=
<?xml version="1.0" encoding="utf-8"?><Field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="Level" UniqueName="[Financial Data Month Validation].[Month Validation Status].[Month Validation Status].ALLMEMBERS" />
I tried ALLMEMBERS, CLOSED, OPEN and some other variations. I m new to this but i have been able to manually create fields before. I think its the two header columns crating my problem here. Any help?

Entity Data Model Designer not showing tables

I am trying to create a Entity Data Model via an existing database,
So i follow these steps in visual studio 2010:
Add new Item->Entity Data Model
Select "Generate From Database"
Select a connection string, test the connection string and its ok
Select the tables, stored procs etc to import, no tables show up at this point, but i do check the "tables" selection - im assuming tho that it should list my tables here.
Then after these steps the Entity Data Model visual tool (ie. double click on .edmx file) shows no tables - i have tables in my database, and the username and pass im using to connect has permissions to access these tables ok.
thanks.
Open your edmx file in a text editor. If you see the tables in the file but not in the designer, try clearing out all the EntitySet nodes and EntityType nodes, save the file, then go back to Visual Studio and try the Update Model from Database again.
<edmx:StorageModels>
<Schema Namespace="myModel.Store">
<EntityContainer Name="MyModelStoreContainer">
delete-> <EntitySet Name="Table1" ... />
delete-> <EntitySet Name="Table2" ... />
</EntityContainer>
delete-> <EntityType Name="Table1">...</EntityType>
delete-> <EntityType Name="Table2">...</EntityType>
</Schema></edmx:StorageModels>
I also had a similar problem. But in my case, it was due to missing Primary Key in the selected table. So, I added a primary key, and updated the model from the Database.
After that, I could see the table, and all the columns!
i has the same problem, i solved adding in the DataConnection filter adding all the schemas, i don't now exactly wath table has missing index or primery keys, etc, but doing this i solve and show all the data.

NHibernate 3.x deletes child entities when combining LINQ paging, many-to-many, and subselect fetch

Our application has the concept of Stories and the concept of Tags. A story can have many tags applied to it, and a tag can be applied to many stories, making the relationship many-to-many. The two tables, Stories and Tags are bridged with a third, StoriesToTags.
The relevant pieces of the mapping files are as follows:
Here's the mapping from Story to Tag:
<class name="Story" table="Stories">
...
<set fetch="subselect" name="Tags" table="StoriesToTags">
<key>
<column name="StoryId" />
</key>
<many-to-many class="Tag">
<column name="TagId" />
</many-to-many>
</set>
</class>
And the inverse relationship from Tag to Story:
<class name="Tag" table="Tags">
...
<set fetch="subselect" inverse="true" name="Stories" table="StoriesToTags">
<key>
<column name="TagId" />
</key>
<many-to-many class="Story">
<column name="StoryId" />
</many-to-many>
</set>
</class>
As you can see, we're using the subselect fetch strategy to avoid the N+1 query problem. Everything works great, until you attempt to page a result using LINQ:
IQueryable<Story> stories = GetStories(...).TakePage(pageNumber, pageSize);
After running this query, NHibernate deletes the relationships (records in StoriesToTags) for all stories that were not loaded in the query. It only seems to occur when the tags are specifically loaded (that is, the subselect is triggered). The relationships are not deleted if we switch to a join or select fetch strategy, but that causes N+1 queries to be executed.
My best guess is that NHibernate thinks the tags have been orphaned, but we haven't set any cascades on the collections. Also, as far as I can tell, setting a cascade has no effect.
This process worked great under NHibernate 2.x and NHibernate.Linq. We didn't see the issue with deletion occur until we moved to NHibernate 3.x, which has LINQ support built-in. I'm not sure it makes a difference, but for what it's worth, we're using SQL Server with identity keys.
Any thoughts? I initially thought I was doing something insanely stupid, but I've tried basically every permutation of mapping and we can't seem to eliminate the issue.
Edit: Another interesting piece of information. If you call session.IsDirty() before closing the session, the issue doesn't occur. I suspect that this is because collection changes aren't persisted between flushes, but I can't decipher NHibernate's source well enough to know for certain.
have you set up in mapping of the entity : Cascade.None() this will stop deleting anything else except the entity.
This might help: http://ayende.com/blog/1890/nhibernate-cascades-the-different-between-all-all-delete-orphans-and-save-update
Can you give us some clue at what you are trying to achieve here ? I never experimented with a specified fetch on a many-to-many, but me thinks it got something to do with some sort of explicit cascade= all for a many to many.

How to programmatically hide a linq-to-sql column on a datagridview?

I'm binding a linq Query to a datagridview for the purposes of allowing a user to insert/update/delete. However I'd like to hide the Id column. but I'd rather not hard code the
datagridview.columns[id].visible=false
In the event the id column name changes. I've read that you can walk through reflection to get a run-time list of columns, but I can't have that checked at design-time for a column name. Is it possible?
If I change the query to not include the ID, then I'm hard coding the column list instead of the id column name, so if columns were added, I'd have to go manually update there instead.
If you're using Winforms, then you should have a BindingSource on your Form that is typed to your LINQ-to-SQL type. If you do this, then you'll get full designer support for all of the fields available on that class.
If you're doing a lot of data binding work with LINQ-to-SQL entities (or any other classes, for that matter), I highly recommend checking into HyperDescriptor by Mark Gravell. It speeds up the UI data binding performance considerably by bypassing repeated runtime invocations of the properties on the classes.
Couldn't you do it in the html? Or are you using ASP.NET?
<asp:BoundField DataField="id" Visible="false" />

Resources