ADO.NET Entity Framework and LINQ to Entities ForumFeedback and questions related to the current versions of the ADO.NET Entity Framework and LINQ to Entities including object-relational mapping and entity data modeling.© 2009 Microsoft Corporation. All rights reserved.Wed, 25 Nov 2009 12:03:17 Z87fece06-ac7e-4c8a-af2d-f163c38c59e1http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/a0d4a283-c2b6-4d81-bb4b-fd96ef47a0e8http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/a0d4a283-c2b6-4d81-bb4b-fd96ef47a0e8Maxbl4http://social.msdn.microsoft.com/Profile/en-US/?user=Maxbl4A dependent property in a ReferentialConstraint is mapped to a storage-generated column. Column: 'ID'.Hi everyone! I searched the net, but couldn`t find the answer. <div>I have two tables: Content with primary key ID, which is bigint and identity</div> <div>and second table Topic which has some other fields and is linked to Content by ID.</div> <div>Content [ID, ...] Primary key, bigint, identity</div> <div>Topic [ID, ...] primary key, bigint, foreign key from Content.ID</div> <div>Topic inherits Content, so Content is the base table and Topic is dependent.</div> <div>I generate an EDM model and can not insert any data into database because on SaveChages I get</div> <div> <div>&quot;A dependent property in a ReferentialConstraint is mapped to a storage-generated column. Column: 'ID'.&quot;</div> <div>As I understand this means, that when entity inserts data into Content it gets the database generated value of ID, but it can not use this value to immediately insert it into Topic.</div> <div>What should I do? Are there any workarounds?</div> <div>I know I can turn off identity in Content and set ID manually, but that will give me many problems with generating unique keys.</div> <div>Also I considered using Guid as primary key, but values from this field will be exposed to users through URL and I want to make clean looking URLs</div> <div><br/></div> </div> <div><br/></div>Wed, 17 Jun 2009 12:46:54 Z2009-11-25T12:03:17Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/a6948120-1d82-429d-a347-caa33d7b05b5http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/a6948120-1d82-429d-a347-caa33d7b05b5heklahttp://social.msdn.microsoft.com/Profile/en-US/?user=heklaHow to set Guid from EFHi<br/> <br/> I am new to EF. I have a DB with multiple tables, all tables have ID col as PK (auto increment witch works without a problem) rowguid col and date modifies col. the col have defaults in db as newid() (rowguid) and getdate() (modified date). This works fine when I add a row in SQL Management studio but what I wonder is how do I get this to work trough EF. <br/> <br/> I have a small table with 4 col. CustomerID (PK)(int), CustomerName(nvarchar), rowguid(uniqueidentifier) and modifieddate(datetime). Now when I want to add a new Customer i run this. <br/> <br/> <pre lang="x-c#"> var customer = new Customer<br/> {<br/> CustomerName = &quot;New Customer3&quot;,<br/> ModifiedDate = DateTime.Now<br/> };</pre> this adds a new customer in my db with a new ID, Name = &quot;New customer3&quot; and modified date = DateTime.Now but my rowguid is 00000000-0000-0000-0000-000000000000 ...I have tried to add RowGuid = new Guid() but the result is the same. <br/> <br/> Any idea??<br/> <br/> ThanksWed, 25 Nov 2009 10:14:29 Z2009-11-25T10:14:29Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/426dc409-5958-4572-9ad2-13128918910chttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/426dc409-5958-4572-9ad2-13128918910cesabedevhttp://social.msdn.microsoft.com/Profile/en-US/?user=esabedevEntity inheritance makes big SQLsWe are developing an application with a base entity with more than 10 childs (which inherited from it).<br/> <br/> When we make any request with Linq to the base entity we get a SQL statement with a &quot;UNION ALL&quot; for each child. To make a Count() over the base entity it takes near one second and getting only one row can takes two seconds.<br/> <br/> For this code:<br/> <br/> <pre lang="x-c#">public bool Exists(int appId, string loginName, DateTime userRegDate, long ahsayId) { var backupsets = from backupset in _entities.AhsayBackupSets where backupset.User.Appliance.Id == appId &amp;&amp; backupset.User.LoginName == loginName &amp;&amp; backupset.User.RegistrationDate == userRegDate &amp;&amp; backupset.AhsayId == ahsayId select backupset; return backupsets.Count() &gt; 0; }</pre> <br/> <br/> We get this SQL sentence:<br/> <br/> <pre lang=x-sql>exec sp_executesql N'SELECT [GroupBy1].[A1] AS [C1] FROM ( SELECT COUNT(1) AS [A1] FROM [dbo].[AhsayBackupSets] AS [Extent1] LEFT OUTER JOIN (SELECT [UnionAll9].[C1] AS [C1] FROM (SELECT [UnionAll8].[C1] AS [C1] FROM (SELECT [UnionAll7].[C1] AS [C1] FROM (SELECT [UnionAll6].[C1] AS [C1] FROM (SELECT [UnionAll5].[C1] AS [C1] FROM (SELECT [UnionAll4].[C1] AS [C1] FROM (SELECT [UnionAll3].[C1] AS [C1] FROM (SELECT [UnionAll2].[C1] AS [C1] FROM (SELECT [UnionAll1].[Id] AS [C1] FROM (SELECT [Extent2].[Id] AS [Id] FROM [dbo].[AhsayOracleBackupSets] AS [Extent2] UNION ALL SELECT [Extent3].[Id] AS [Id] FROM [dbo].[AhsaySystemStateBackupSets] AS [Extent3]) AS [UnionAll1] UNION ALL SELECT [Extent4].[Id] AS [Id] FROM [dbo].[AhsayMysqlBackupSets] AS [Extent4]) AS [UnionAll2] UNION ALL SELECT [Extent5].[Id] AS [Id] FROM [dbo].[AhsayMssqlBackupSets] AS [Extent5]) AS [UnionAll3] UNION ALL SELECT [Extent6].[Id] AS [Id] FROM [dbo].[AhsayFileBackupSets] AS [Extent6]) AS [UnionAll4] UNION ALL SELECT [Extent7].[Id] AS [Id] FROM [dbo].[AhsayExchangeServerBackupSets] AS [Extent7]) AS [UnionAll5] UNION ALL SELECT [Extent8].[Id] AS [Id] FROM [dbo].[AhsayDominoBackupSets] AS [Extent8]) AS [UnionAll6] UNION ALL SELECT [Extent9].[Id] AS [Id] FROM [dbo].[AhsayNotesBackupSets] AS [Extent9]) AS [UnionAll7] UNION ALL SELECT [Extent10].[Id] AS [Id] FROM [dbo].[AhsayShadowProtectBackupSets] AS [Extent10]) AS [UnionAll8] UNION ALL SELECT [Extent11].[Id] AS [Id] FROM [dbo].[AhsayWindowsSystemBackupSets] AS [Extent11]) AS [UnionAll9] UNION ALL SELECT [Extent12].[Id] AS [Id] FROM [dbo].[AhsayExchangeMailBackupSets] AS [Extent12]) AS [UnionAll10] ON [Extent1].[Id] = [UnionAll10].[C1] LEFT OUTER JOIN [dbo].[AhsayUsers] AS [Extent13] ON [Extent1].[AhsayUserId] = [Extent13].[Id] INNER JOIN [dbo].[AhsayUsers] AS [Extent14] ON [Extent1].[AhsayUserId] = [Extent14].[Id] WHERE ([Extent13].[ApplianceId] = @p__linq__0) AND ([Extent13].[LoginName] = @p__linq__1) AND ([Extent14].[RegistrationDate] = @p__linq__2) AND ([Extent1].[AhsayId] = @p__linq__3) ) AS [GroupBy1]',N'@p__linq__0 int,@p__linq__1 nvarchar(4000),@p__linq__2 datetime,@p__linq__3 bigint',@p__linq__0=2,@p__linq__1=N'antonio',@p__linq__2='2009-10-22 18:07:17',@p__linq__3=1256305376226</pre> <br/> <br/> Is there some way to reduce the SQL overhead? We know we can use stored procedures for heavy sentences but we don't want to lose the Linq flexibility.<br/> <br/> Thanks in advance.Wed, 25 Nov 2009 09:25:17 Z2009-11-25T09:25:17Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/12191f0d-3010-425d-9c52-ed0542458eafhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/12191f0d-3010-425d-9c52-ed0542458eafStefanOlsonhttp://social.msdn.microsoft.com/Profile/en-US/?user=StefanOlsonError 3034: An entity from one EntitySet is mapped to a row that is also mapped to an entity from another EntitySet<p align=left><font face=Arial size=2></font> </p> <p>Hi,</p> <p align=left> </p> <p align=left>I've wasted all afternoon attempting to get the entity designer doing what I expect.  I have added a new inheritance level on most of my objects. Is very frustrating that every time you change a classes inheritance, the designer loses all that classes relationships.</p> <p> </p> <p align=left>Eventually I thought I had it right, only to find a new problem which I haven't yet found a solution for.  I get this error when I build:</p> <p>Error 3034: Problem in Mapping Fragments starting at lines 2495, 2504: An entity from one EntitySet is mapped to a row that is also mapped to an entity from another EntitySet with possibly different key. Ensure these two mapping fragments do not map two unrelated EntitySets to two overlapping groups of rows.<br><br>The code it is referring to is:</p><font color="#0000ff" size=2><font color="#0000ff" size=2> <p align=left> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div><font color="#0000ff" size=2><font color="#0000ff" size=2> <p align=left>&lt;</font></font><font color="#a31515" size=2><font color="#a31515" size=2>AssociationSetMapping</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>Name</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>FK_Pictures_NextPicture</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>TypeName</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>bptour_DataModel.FK_Pictures_NextPicture</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>StoreEntitySet</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>Pictures</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>&gt;</p> <p align=left>&lt;</font></font><font color="#a31515" size=2><font color="#a31515" size=2>EndProperty</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>Name</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>Picture1</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>&gt;</p> <p align=left>&lt;</font></font><font color="#a31515" size=2><font color="#a31515" size=2>ScalarProperty</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>Name</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>TourObjectID</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>ColumnName</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>PictureID</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2> /&gt;</p> <p align=left>&lt;/</font></font><font color="#a31515" size=2><font color="#a31515" size=2>EndProperty</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>&gt;</p> <p align=left>&lt;</font></font><font color="#a31515" size=2><font color="#a31515" size=2>EndProperty</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>Name</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>Picture</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>&gt;</p> <p align=left>&lt;</font></font><font color="#a31515" size=2><font color="#a31515" size=2>ScalarProperty</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>Name</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>TourObjectID</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>ColumnName</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>NextPictureID</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2> /&gt;</p> <p align=left>&lt;/</font></font><font color="#a31515" size=2><font color="#a31515" size=2>EndProperty</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>&gt;</p> <p align=left>&lt;</font></font><font color="#a31515" size=2><font color="#a31515" size=2>Condition</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>ColumnName</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>NextPictureID</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>IsNull</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>false</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2> /&gt;</p> <p align=left>&lt;/</font></font><font color="#a31515" size=2><font color="#a31515" size=2>AssociationSetMapping</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>&gt;</p> <p align=left>&lt;</font></font><font color="#a31515" size=2><font color="#a31515" size=2>AssociationSetMapping</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>Name</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>FK_Pictures_PrevPictures</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>TypeName</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>bptour_DataModel.FK_Pictures_PrevPictures</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>StoreEntitySet</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>Pictures</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>&gt;</p> <p align=left>&lt;</font></font><font color="#a31515" size=2><font color="#a31515" size=2>EndProperty</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>Name</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>Picture1</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>&gt;</p> <p align=left>&lt;</font></font><font color="#a31515" size=2><font color="#a31515" size=2>ScalarProperty</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>Name</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>TourObjectID</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>ColumnName</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>PictureID</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2> /&gt;</p> <p align=left>&lt;/</font></font><font color="#a31515" size=2><font color="#a31515" size=2>EndProperty</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>&gt;</p> <p align=left>&lt;</font></font><font color="#a31515" size=2><font color="#a31515" size=2>EndProperty</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>Name</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>Picture</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>&gt;</p> <p align=left>&lt;</font></font><font color="#a31515" size=2><font color="#a31515" size=2>ScalarProperty</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>Name</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>TourObjectID</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2> </font></font><font color="#ff0000" size=2><font color="#ff0000" size=2>ColumnName</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>=</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>PrevPictureID</font></font><font size=2>&quot;</font><font color="#0000ff" size=2><font color="#0000ff" size=2> /&gt;</p> <p align=left>&lt;/</font></font><font color="#a31515" size=2><font color="#a31515" size=2>EndProperty</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>&gt;</p> <p align=left>&lt;/</font></font><font color="#a31515" size=2><font color="#a31515" size=2>AssociationSetMapping</font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>&gt;</font></font></p> <p align=left> </p></div></div> <p align=left> </p></font></font> <p></p><font color="#0000ff" size=2><font color="#0000ff" size=2> <p> </p> <p align=left>And I have several similar associations with exactly the same problem, even though this problem did not exist even after changing the inheritance of that particular object.</p> <p align=left> </p> <p align=left>TourObjectID is the primary key defined in the parent class PictureID being the primary key in this particular class.</p> <p align=left> </p> <p align=left>Unfortunately I have been unable to come up with a solution to this particular problem, so I hope someone can point me in a direction, so I can actually work on my project again.</font></font></p> <p> </p> <p align=left>...Stefan</p>Tue, 26 Aug 2008 06:42:01 Z2009-11-25T08:17:24Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/c5a7a766-9b02-4ae2-be60-a2605983701dhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/c5a7a766-9b02-4ae2-be60-a2605983701dMichael Taohttp://social.msdn.microsoft.com/Profile/en-US/?user=Michael%20Tao"The underlying provider failed on Open." when invoking the SaveChanges method<p align=left><font face=Arial size=2>I wanna write a demo about the ado.net entity framework. But i find a strange problem whenever i invoke the saveChanges method.</font></p> <p>            using (NorthwindEntities myDb = new NorthwindEntities())<br>            {<br>                Customers customer = new Customers();</p> <p>                Random rm = new Random();</p> <p>                customer.CustomerID = &quot;A&quot; + rm.Next(9999).ToString();<br>                customer.CompanyName = &quot;EntLib.com Forum&quot;;<br>                customer.Address = &quot;<a title="http://www.EntLib.com" href="http://www.EntLib.com">http://www.EntLib.com</a>&quot;;</p> <p>                myDb.AddToCustomers(customer);</p> <p>                int count = myDb.SaveChanges();</p> <p>                txtCustomerID.Text = customer.CustomerID;<br>            }</p> <p align=left> </p> <p align=left>i just map the Northwind db and insert a recond into the customers table. However, the error &quot;<strong>The underlying provider failed on Open.&quot;</strong>  is thrown. Can anyone help me resolve it? The following is the connectstring.</p> <p align=left> </p> <p align=left>  &lt;connectionStrings&gt;<br>    &lt;add name=&quot;NorthwindEntities&quot; connectionString=&quot;metadata=res://*/NorthwindDB.csdl|res://*/NorthwindDB.ssdl|res://*/NorthwindDB.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;Data Source=LSMIS006;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=True&amp;quot;&quot; providerName=&quot;System.Data.EntityClient&quot; /&gt;<br>  &lt;/connectionStrings&gt;</p>Sun, 24 Aug 2008 13:51:15 Z2009-11-25T06:34:43Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/1e1152c6-beab-4945-9b00-69770440999ehttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/1e1152c6-beab-4945-9b00-69770440999edzFactorhttp://social.msdn.microsoft.com/Profile/en-US/?user=dzFactorUpdate Model From Database ProblemFor a while I have been suspecting that &quot;Update Model from Database&quot; feature in edmx diagram is not working as I expected. So, I decided to test it. I created a simple database with a single table from which I created the edmx file. Then I added a column to the table and used &quot;Update Model from Database&quot; to reflect the change in the model. That step worked as expected and the model showed the additional column. Then I went back to the database and removed that column and tried again to Update the Model using the same steps as before. This time the model did not reflected the change. I tried different things to force the change but nothing seems to be working. <br/>Finally I tried a drastic measure and deleted the edmx file and rectreated it from scratch. during this step I discovered another issue. I could not reuse the same entity name because the system complained that the name is already in use. This issue represent a compound problem, since now all code refrencing the entity context need to be renamed. Not sure if this issue is a bug or by design. If anyone has an explaination I would greatly appriciate it. The steps I took above are pretty easy to recreate.<br/>Thanks,<br/>ZevTue, 17 Nov 2009 17:45:57 Z2009-11-25T05:44:11Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/e40ebd05-4774-4ac1-8252-1b7f41293117http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/e40ebd05-4774-4ac1-8252-1b7f41293117Bonusnethttp://social.msdn.microsoft.com/Profile/en-US/?user=BonusnetBulk Insert into table - How to manage the transaction?<span>My scenario as follow,<br/>1. Thomas is a Ticket Agent for GSC Bus<br/>2. As Ticket Agent, he have a Prepaid. <br/>3. Let's say, his balance is $125.45<br/>4. Now, he perform purchasing 12 Ticket -- This process only click 1 submit button on front-end, front-end code will doing a looping to hit Stored Procedure<br/>4. Total Amount for 12 Ticket is $130.45 -- at this level, he exceed his prepaid<br/><br/>My question is,<br/>1. How transaction can manage the Atomicity for this Bulk Insert (12 insert into the table)?<br/>2. Where to check the Total of Ticket Amount?<br/>3. Did i need to check the sum of the 12 ticket &lt;= $125.45 at front-end first, then perform the transaction? or check the sum of the 12 ticket &lt;= $125.45 at Back-end (Stored Procedure), then perform the transaction?</span>Wed, 25 Nov 2009 05:23:35 Z2009-11-25T05:23:36Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/baa0bef9-a7b8-4a85-ace5-8103fd401ed6http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/baa0bef9-a7b8-4a85-ace5-8103fd401ed6Olaf Rabbachinhttp://social.msdn.microsoft.com/Profile/en-US/?user=Olaf%20RabbachinLeft Join for a 1:0:1 relationHi folks,<br/> <br/> I have three tables: <em>Contact</em> (C)<em>,</em> <em>ContactAddress</em> (CA) and <em>ContactAddressCategory</em> (CAC). These relate to each other as  1 <em>C</em> : 0..n <em>CA </em> 1..1 <em>CAC</em> . <br/> That is, a contact can have 0 to n addresses (i.e. street, city, etc.). Each address is linked to an address-category (i.e. default address, shipping address, etc.). <em>CAC </em> also has a boolean flag that identifies exactly what address category is the default one.<br/> <br/> In my WPF-app, I have a window that allows for editing <em>Contacts</em> . There, a ComboBox (let's call it <em>cboSearch</em> ) displays all <em>Contacts</em> , allowing users to pick the one to be edited. In <em>cboSearch</em> , I'd like to display the contact's name along with the <span style="text-decoration:underline">first</span> address, if there is any (i.e. if there is a default-category address, use that; otherwise take any other one, or show an empty string if there is none at all). <br/> That said, the data being returned is also being used as the &quot;DataSource&quot; for the window itself. <br/> <br/> I'd appreciate someone giving me a little help on how I'd have to construct the LINQ-query (VB preferred, C# would also do though) - I'm just not getting there ...<br/><hr class="sig">Cheers,<br/>OlafTue, 24 Nov 2009 17:56:56 Z2009-11-25T04:20:33Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/243c01b3-8eeb-4e1c-94f2-9ed9d8d67a1bhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/243c01b3-8eeb-4e1c-94f2-9ed9d8d67a1bMichel Haddad Doumithttp://social.msdn.microsoft.com/Profile/en-US/?user=Michel%20Haddad%20DoumitEntity 4 XML Mapping ? <p>I'm interest on the CodeOnly feature on the Entity Framework 4, and want to know  if there is a way to map the classes by a separated xml file like MappingSource on DLinq, Nhibernate, ... <br/><br/>Tks</p><hr class="sig">Michel Haddad DoumitWed, 25 Nov 2009 01:48:34 Z2009-11-25T02:51:32Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/95c03cfc-7f0b-4f70-b2e1-a53e557a28a0http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/95c03cfc-7f0b-4f70-b2e1-a53e557a28a0bmainshttp://social.msdn.microsoft.com/Profile/en-US/?user=bmainsBest Way to Check For Existence of a Relationship Performance-wiseHello,<br/> <br/> We often want to check that an existing reference (an EntityReference&lt;&gt;) relationship exists.  But I want to see if that relationship exists without having to load the record first.  So consider I queried a LINQ to Entities object from the database... this object (Customer) has a relationship to Region (setup as an EntityReference&lt;&gt; so there is a Region and a RegionReference properties).<br/> <br/> What is the best way to check a relationship existence... will the Entity key always be null in this case, or will the entity key have no related values?  I am thinking of performance; if I don't have to load a relationship, I don't want to have to.  That's what's nice about LINQ to SQL, the foreign or primary key is right in the record itself...<br/> <br/> Thanks.<hr class="sig">http://linkedin.com/in/brianmainsTue, 24 Nov 2009 23:24:34 Z2009-11-25T01:04:02Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/43c75264-fb72-444a-bf15-cec58982fc27http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/43c75264-fb72-444a-bf15-cec58982fc27Gkreerhttp://social.msdn.microsoft.com/Profile/en-US/?user=GkreerHelp with Error 3034 in Entity FrameworkHello, <br/><br/>I'm having serious trouble with error 3034 and i really tried to fix it looking at previous posts but I couldn´t make it.<br/><br/>I need someone who can help me quickly, because this is a job for college and I have only 1 week left!! This is the last thing to finish it!<br/><br/><br/>Thank you very much for you help!<br/><br/>Guillermo Kreer<br/><br/><br/><br/>These are the errors I have (Sorry but my Visual Studio is in spanish) :<br/><br/>Error 9 Error 3034: Hay un problema en los fragmentos de asignación con inicio en las líneas 275, 284: Dos entidades con claves diferentes están asignadas a la misma fila. Asegúrese de que los dos fragmentos de la asignación no asignan dos grupos de entidades con claves solapadas al mismo grupo de filas.<br/> C:\Users\Guille\Desktop\DA2Obligatorio2\DominioEF\HotelBD.edmx 276<br/>Error 10 Error 3034: Hay un problema en los fragmentos de asignación con inicio en las líneas 275, 287: Dos entidades con claves diferentes están asignadas a la misma fila. Asegúrese de que los dos fragmentos de la asignación no asignan dos grupos de entidades con claves solapadas al mismo grupo de filas.<br/> C:\Users\Guille\Desktop\DA2Obligatorio2\DominioEF\HotelBD.edmx 276<br/>Error 11 Error 3034: Hay un problema en los fragmentos de asignación con inicio en las líneas 284, 289: Dos entidades con claves diferentes están asignadas a la misma fila. Asegúrese de que los dos fragmentos de la asignación no asignan dos grupos de entidades con claves solapadas al mismo grupo de filas.<br/> C:\Users\Guille\Desktop\DA2Obligatorio2\DominioEF\HotelBD.edmx 290<br/>Error 12 Error 3034: Hay un problema en los fragmentos de asignación con inicio en las líneas 287, 289: Dos entidades con claves diferentes están asignadas a la misma fila. Asegúrese de que los dos fragmentos de la asignación no asignan dos grupos de entidades con claves solapadas al mismo grupo de filas.<br/> C:\Users\Guille\Desktop\DA2Obligatorio2\DominioEF\HotelBD.edmx 290<br/>Error 13 Error 3034: Hay un problema en los fragmentos de asignación con inicio en las líneas 284, 298: Dos entidades con claves diferentes están asignadas a la misma fila. Asegúrese de que los dos fragmentos de la asignación no asignan dos grupos de entidades con claves solapadas al mismo grupo de filas.<br/> C:\Users\Guille\Desktop\DA2Obligatorio2\DominioEF\HotelBD.edmx 299<br/>Error 14 Error 3034: Hay un problema en los fragmentos de asignación con inicio en las líneas 287, 298: Dos entidades con claves diferentes están asignadas a la misma fila. Asegúrese de que los dos fragmentos de la asignación no asignan dos grupos de entidades con claves solapadas al mismo grupo de filas.<br/> C:\Users\Guille\Desktop\DA2Obligatorio2\DominioEF\HotelBD.edmx 299<br/><br/>This is the XML snippet:<br/><br/>&lt;EntitySetMapping Name=&quot;Reserva&quot;&gt;<br/>            &lt;EntityTypeMapping TypeName=&quot;IsTypeOf(HotelBDModel.Reserva)&quot;&gt;<br/>              &lt;MappingFragment StoreEntitySet=&quot;Reserva&quot;&gt;<br/>                &lt;ScalarProperty Name=&quot;checkout&quot; ColumnName=&quot;checkout&quot; /&gt;<br/>                &lt;ScalarProperty Name=&quot;idReserva&quot; ColumnName=&quot;idReserva&quot; /&gt;<br/>                &lt;ScalarProperty Name=&quot;fechaIngreso&quot; ColumnName=&quot;fechaIngreso&quot; /&gt;<br/>                &lt;ScalarProperty Name=&quot;fechaSalida&quot; ColumnName=&quot;fechaSalida&quot; /&gt;<br/>                &lt;ScalarProperty Name=&quot;ocupada&quot; ColumnName=&quot;ocupada&quot; /&gt;<br/>              &lt;/MappingFragment&gt;<br/>            &lt;/EntityTypeMapping&gt;<br/>            &lt;EntityTypeMapping TypeName=&quot;HotelBDModel.ReservaFactura&quot;&gt;<br/>              &lt;MappingFragment StoreEntitySet=&quot;Reserva&quot;&gt;<br/>                &lt;ScalarProperty Name=&quot;idReserva&quot; ColumnName=&quot;idReserva&quot; /&gt;&lt;/MappingFragment&gt;&lt;/EntityTypeMapping&gt;<br/>            &lt;EntityTypeMapping TypeName=&quot;HotelBDModel.ReservaFacturaWeb&quot;&gt;<br/>              &lt;MappingFragment StoreEntitySet=&quot;Reserva&quot;&gt;<br/>                &lt;ScalarProperty Name=&quot;idReserva&quot; ColumnName=&quot;idReserva&quot; /&gt;&lt;/MappingFragment&gt;&lt;/EntityTypeMapping&gt;&lt;/EntitySetMapping&gt;<br/>          &lt;AssociationSetMapping Name=&quot;FK_Reserva_Cliente&quot; TypeName=&quot;HotelBDModel.FK_Reserva_Cliente&quot; StoreEntitySet=&quot;Reserva&quot;&gt;<br/>            &lt;EndProperty Name=&quot;Cliente&quot;&gt;<br/>              &lt;ScalarProperty Name=&quot;idCliente&quot; ColumnName=&quot;nroCliente&quot; /&gt;<br/>     &lt;/EndProperty&gt;<br/>     &lt;EndProperty Name=&quot;Reserva&quot;&gt;<br/>              &lt;ScalarProperty Name=&quot;idReserva&quot; ColumnName=&quot;idReserva&quot; /&gt;<br/>            &lt;/EndProperty&gt;Tue, 24 Nov 2009 21:16:56 Z2009-11-25T01:00:39Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/0a446dcd-cf39-4e85-9b2f-a3bf9d33e8e2http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/0a446dcd-cf39-4e85-9b2f-a3bf9d33e8e2Lisa Tatumhttp://social.msdn.microsoft.com/Profile/en-US/?user=Lisa%20TatumEntity Framework + Windows Forms provide a bad software architecture base ?Hello,<br/> <br/> I do not like Entity Framework together with Windows Forms (Data Binding). Both together provide a bad software architecture, why? I am gonna show here:<br/> <br/> Lets assume I want to <strong>add </strong> an <strong>Entity </strong> called <strong>Customer </strong> to my database. I use MVP design pattern for Windows Forms apps.<br/> <br/> I can add this entity in 2 ways:<br/> <br/> In my View/Form class:<br/> <br/> <br/>   bindingSourceCustomer.DataSource = queryCustomers;<br/> <br/>   Customer customer = new Customer();<br/>                  customer.FirstName = &quot;Lisa&quot;;<br/>                  customer.LastName = &quot;Tatum&quot;;<br/> <br/>    Way 1.) bindingSourceCustomer.Add(customer); databaseContext.SaveChanges(); <br/> <br/>                -&gt; <strong>BAD </strong> , because the model/entity Customer is instantiated in the VIEW what has nothing to do there.<br/> <br/>    Way 2.) presenter.AddCustomer();<br/>                especially in PRESENTER class:        <br/> <br/>                public void AddCustomer()<br/>               {<br/>                     Customer customer = new Customer();<br/>                     customer.FirstName = view.FirstName;<br/>                     customer.LastName = view.LastName;<br/> <br/>                     databaseContext.AddObject(&quot;Customer&quot;, customer);<br/>                     databaseContext.SaveChanges();<br/>                     <br/>                     var queryCustomer = databaseContext.Customer.Execute(MergeOption.AppendOnly);<br/> <br/>                     view.RebindNewCustomers(queryCustomer);<br/>               }<br/> <br/> VIEW:<br/> <br/> public void RebindNewCustomers(ObjectResult&lt;Customer&gt; queryCustomer)<br/> {<br/>      bindingSourceCustomer.DataSource = queryCustomer;<br/> }<br/> <br/> <br/>          -&gt; <strong>BAD</strong> , because for every entity change in the GUI I have to make an extra roundtrip to the database and query it for the new added customer.<br/>                       <br/>              What a waste of ressource, impossible to use in a client/server application.<br/> <br/> Let me know your thoughts, please!Tue, 24 Nov 2009 20:39:43 Z2009-11-24T21:40:46Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/18f0c4ce-64a3-46fe-b69c-88cf9ac0cdf1http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/18f0c4ce-64a3-46fe-b69c-88cf9ac0cdf1Lisa Tatumhttp://social.msdn.microsoft.com/Profile/en-US/?user=Lisa%20Tatummake a scalar property a unique field ?Hello,<br/> <br/> Event:<br/> <br/> eventID int identity (PK)<br/> eventname varchar (Unique)<br/> <br/> How can I set my eventname field as a unique field so inserting of 2x &quot;party&quot; is not possible.<br/> <br/> Haven`t found anything in Visual Studio ??Sat, 21 Nov 2009 11:03:10 Z2009-11-24T19:44:10Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/9f783809-e0a7-4fac-8a84-79d16852a742http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/9f783809-e0a7-4fac-8a84-79d16852a742MGoyalhttp://social.msdn.microsoft.com/Profile/en-US/?user=MGoyalUnusual exception working with Entity Framework in Multithreding environmentI have a database model which I have imported in my code using Entity Framework(EF). There are some entities that are created by EF. I retrieve x no of entities using Function import and then my business logic works directly on those retrieved entities and updates certain properties based on some logic. what I am doing is, for each entity i am creating a new thread and applying my business logic on them using an action chain that I have built. So, there is one entity passed to a thread and all of them are being processed asynchronously. The problem now is that I keep on getting this weird exception every now and then (the exception is not consistent, it comes from any action in the action chain for any property), <em><strong>&quot;EntityMemberChanged or EntityComplexMemberChanged was called without first calling EntityMemberChanging or EntityComplexMemberChanging on the same change tracker with the same property name. For information about properly reporting changes, see the Entity Framework documentation&quot;. </strong></em> <div><strong><br/></strong></div> <div>To prevent this I created partial class for the entities and created wrapper properties over my entity properties and in the set of my wrapper properties, I am setting the main entity property inside a <em><strong>lock </strong><span style="font-style:normal">so that if it is because of multi threading situation, that gets synchronized, but I am still getting that exception. Can anybody be of help in this?. I have tried so many things but nothing is actually working for me. Please guide me if I am doing something wrong.</span></em></div> <div>The other thing that may be of importance is that my entity has many Nullable properties but the wrapper properties in my other partial class are not Nullable and I am setting these properties inside the lock.</div>Fri, 20 Nov 2009 05:23:19 Z2009-11-24T19:16:36Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/7e38d4bf-1767-4689-a97e-131e7bb8b348http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/7e38d4bf-1767-4689-a97e-131e7bb8b348satenhttp://social.msdn.microsoft.com/Profile/en-US/?user=satenTo query directly the Storage Model using EF 4.0<p><span style="" lang=EN-US><span style="font-size:small"><span style="font-family:Times New Roman">Can i get the column names of my table which are not mapped with my Entity in EF 4.0.</span></span></span></p> <p><span style="" lang=EN-US><span style="font-size:small"><span style="font-family:Times New Roman">for Example</span></span></span></p> <p><span style="" lang=EN-US><span style="font-size:small"><span style="font-family:Times New Roman">if i have a Table GL_Book( ID, Name , Description ,Cost)</span></span></span></p> <p><span style="" lang=EN-US><span style="font-size:small"><span style="font-family:Times New Roman">and in the Conceptual model i have mapped it to Book(Name, Description).</span></span></span></p> <p><span style="" lang=EN-US><span style="font-size:small"><span style="font-family:Times New Roman">Can i access the remaining columns of my GL_Book(say cost) table using entity framework in my code(by querying the storage model)?<br/></span></span></span></p> <p><span style="" lang=EN-US><span style="font-size:small"><span style="font-family:Times New Roman">i know using the &quot;<span style="font-size:11pt;color:#1f497d;font-family:'Calibri','sans-serif'" lang=EN-US>metadataworkspace&quot; i can query my entity but can we use this to query the storage model. </span><br/>if yes can get the columns of my table which is extensible and my clients have extended them at Run time and i want to access their values at the runtime.</span></span></span></p> <p><span style="" lang=EN-US><span style="font-size:small"><span style="font-family:Times New Roman">Thanks &amp; Regards</span></span></span></p> <p><span style="" lang=EN-US><span style="font-size:small"><span style="font-family:Times New Roman">Satender Kumar</span></span></span></p>Tue, 24 Nov 2009 11:01:54 Z2009-11-24T18:46:43Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/c1e11ac3-f80b-4f29-bf36-323248930558http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/c1e11ac3-f80b-4f29-bf36-323248930558Patrik Löwendahlhttp://social.msdn.microsoft.com/Profile/en-US/?user=Patrik%20L%u00f6wendahlInvalid FORMATETC Structure<p>Hi, </p> <p>I'm getting this error: Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC)) when creating a mapfile from existing data store. This is done in a dll. Using the wizard from a console application project works fine though.</p>Sun, 04 Mar 2007 14:32:20 Z2009-11-24T16:30:04Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/9c6c3a6a-47e1-43de-a572-d607c256e358http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/9c6c3a6a-47e1-43de-a572-d607c256e358Sudheer Kumarhttp://social.msdn.microsoft.com/Profile/en-US/?user=Sudheer%20KumarEntity Framework & Transaction Scope usageI am having an issue using Transaction Scope with Entity Framework.<br/> I get an exception : <strong>MSDTC on server '&lt;Server Name&gt;' is unavailable.</strong> <br/> As per the suggestion from this article : http://msdn.microsoft.com/en-us/library/bb738698.aspx<br/> I have the following piece of code to prevent escalating the transactions by MSDTC<br/> <br/> <p>using (TransactionScope ts = new TransactionScope()) <br/> { <br/>     context.Connection.Open();</p> <p>    //Add Operation : context.SaveChanges();</p> <p>    //Select from a table</p> <p>   Table t = context.Table.where (o =&gt; o.ID == someID).First();   <strong>//Getting the above exception here</strong></p> <p>   //Add Operation : context.SaveChanges();</p> <p>    ts.Complete();</p> <p>}</p> <p>catch (Exception ex)</p> <p>{</p> <p>      //Handle Exception</p> <p>}</p> <p>finally <br/> { <br/>       if (context.Connection.State == ConnectionState.Open) <br/>       { <br/>            context.Connection.Close(); <br/>       } <br/> }</p> <p> </p> <p>I have MSDTC service stopped on my machine.</p> <p>If I start it, (Run-&gt; dcomcnfg), then it works fine.</p> <p>Why is it throwing the exception when I turn off MSDTC?</p> <p>I am using a single connection string and context. I just want to make sure that thry don't unnecessarily get escalated to distributed transactions.</p> <p>Please advice..</p> <p> </p> <p>Thanks!</p> <p> </p> <br/>Mon, 23 Nov 2009 18:34:37 Z2009-11-24T16:05:23Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/862abdae-b63f-45f5-8a6c-0bdd6eeabfdbhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/862abdae-b63f-45f5-8a6c-0bdd6eeabfdbMarcelNihttp://social.msdn.microsoft.com/Profile/en-US/?user=MarcelNiGetting SqlException "Invalid column name 'User_Id' from EF4 code-only I got a strange behaviour with code only (EF CTP) where I get an EntityCommandExecutionException, and the inner exception is a SQLException saying: Invalid column name 'User_Id'.<br/><br/>The strange thing with this is that my POCO does not contain a User_Id (there is even no such field/property in my whole solution).<br/><br/>Here is the stack trace from the EntityCommandExecutionException:<br/><br/>   at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)<br/>   at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)<br/>   at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)<br/>   at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable&lt;T&gt;.GetEnumerator()<br/>   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)<br/>   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)<br/>   at Repositories.EF.EFRepository`2.GetAll() in C:\Projects\Repositories.EF\EFRepository.vb:line 64<br/>   at epositories.Website.EFBlogAggregateRepository.GetAllBlogs() in C:\Projects\Repositories.Website\EntityFramework\Repositories\AggregateRepositories\EFBlogAggregateRepository.vb:line 18<br/>   at Repositories.Test.BlogTest.GetAllBlogs() in C:\Projects\Repositories.Test\BlogTest.vb:line 70<br/><br/>Does anybody have an idea what is going on here?Tue, 24 Nov 2009 13:27:04 Z2009-11-24T13:58:42Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/df1c00e7-00a4-47bd-8fab-c83e97673942http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/df1c00e7-00a4-47bd-8fab-c83e97673942Werner Clausenhttp://social.msdn.microsoft.com/Profile/en-US/?user=Werner%20ClausenEF: How to avoid string truncation sql errorHi,<br/><br/>I bet you were going to write &quot;Make sure the string isnt too long&quot; :)<br/>But isn't there some way to let EF truncate strings?<br/><br/>--Fri, 20 Nov 2009 12:37:28 Z2009-11-24T14:36:52Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/ce1f46c6-a5fe-4081-95ce-8fa14e98858fhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/ce1f46c6-a5fe-4081-95ce-8fa14e98858fNeilAldersonhttp://social.msdn.microsoft.com/Profile/en-US/?user=NeilAldersonDefault ValuesHi,<br/> <br/> I'm new to EF and just playing around with it currently. I'm experimenting with creating a WCF web service API using EF to query the database and provide data classes for the client in a shared interface dll. I'd done this in LINQ to SQL and it worked well but due to recent news wanted to see how well it would port to EF.<br/> <br/> I want the client to be able to instantiate an EF generated class from the shared interface dll so that he can pass it to my web method as a set of query parameters. E.g. if the &quot;Name&quot; property has a value, add it to the where clause on the server side etc.<br/> <br/> Problem is the generated classes seem to constrain on Not Null fields but don't make use of the default value that was set in the database. This means when the client instantiates the object with just one or two fields, EF complains that all the other fields can't be left as null. Does this mean the client has to fill in every single &quot;not null&quot; field just when he wants to query on one thing?<br/> <br/> If this is a limitation in using EF then the alternative would be to create a set of classes that mirrors the generated ones, specifically for creating query parameters! That seems pointless when you already have the classes made for you. Is there a better way? Or should I just go back to LINQ to SQL?Wed, 18 Nov 2009 16:36:57 Z2009-11-24T18:48:29Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/985a1048-cf56-4bb0-b664-61fbf4957890http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/985a1048-cf56-4bb0-b664-61fbf4957890ag.mothilalhttp://social.msdn.microsoft.com/Profile/en-US/?user=ag.mothilalADO.NET entity framework from MS-ACCESS database<strong>        Please can u guide me how to connect ms-access.mdb file through ado.net entity model</strong> <strong>using vs2008.</strong> <br/> <strong>I am already installed vs2008sp1 and .net3.5sp1. </strong>Fri, 20 Nov 2009 10:14:37 Z2009-11-24T09:49:36Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/ccacf991-5297-48c9-967a-fdf64542c2aahttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/ccacf991-5297-48c9-967a-fdf64542c2aaCristian Prevedellohttp://social.msdn.microsoft.com/Profile/en-US/?user=Cristian%20PrevedelloNavigation properties are null on Multiple Entitity setGreetings,<br/> <br/> we imported from the db a table in one entity. since such table is very big, we copied and pasted the entity to split properties into several entities. We then added associations to the model (1 to 1) to relate all our entities. The model is working great (update, dbload), except for added entities: navigational properties are always null.<br/> <br/> MainEntity<br/> Id<br/> Prop1<br/> Prop2<br/> Prop3<br/> Prop4<br/> Prop5<br/> <br/> We copy and pasted the entity and removed Prop4 and Prop5 from MainEntity, and Prop1, Prop2, and Prop3 from new entity. Added association.<br/> <br/> so we have the following situation:<br/> <br/> MainEntity<br/> Id<br/> Prop1<br/> Prop2<br/> Prop3<br/> Details ---&gt; Navigation property<br/> <br/> MainEntityDetails<br/> Id<br/> Prop4<br/> Prop5<br/> MainEntity ---&gt; Navigation property<br/> <br/> With such model loading and lazy loading from database works correctly. What does not work out of the box is the insertion of new entities:<br/> <br/> MainEntity e=context.MainEntitySet.CreateObject();<br/> <br/> e.ID = 0;<br/> <br/> context.MainEntitySet.AddObject(e);<br/> <br/> <br/> Unfortunately e.Details is always null. <br/> <br/> What's wrong?<br/> <br/>Sun, 22 Nov 2009 11:28:11 Z2009-11-24T08:50:22Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/61424a1f-b8a3-4041-b0f1-19b5277417e0http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/61424a1f-b8a3-4041-b0f1-19b5277417e0unitizehttp://social.msdn.microsoft.com/Profile/en-US/?user=unitizeID collision with table-per-concrete-typeHey all,<br/><br/>I have an abstract base class EntityBase which does not map to a table and a few derived classes like Empire, City, Building which each map to their own tables.  Each table has an Id field, which on the database is set as an AUTOINCREMENT primary key column.<br/><br/>My problem occurs when trying to add a new Building to the EDM object context, it throws an exception while trying to add the new object due to an ID collision in the City table.  The very next ID to be used in Building is 10, which happens to already be occupied by an existing City row.<br/><br/>Is there a way around this?  I don't mind if each table has a different ID space, but EDM seems to take issue with having the same key within the same EntitySet.  Is the proper fix to define separate EntitySets for each concrete type?  How does that work?  Or is that just a more problematic approach... <br/>Sun, 22 Nov 2009 05:37:08 Z2009-11-24T07:36:03Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/a2415ac1-a3bc-41c9-850d-8cf984368a38http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/a2415ac1-a3bc-41c9-850d-8cf984368a38Radu Olaruhttp://social.msdn.microsoft.com/Profile/en-US/?user=Radu%20OlaruADO.NET Useless Model-Defined FunctionsHello,  <div><br/></div> <div>I have this small complain about Entity Framework 4.0 which I would like to throw in. I have an entity A, which has A.Value1 and A.Value2. These values are in a table - I create the model, everything fine there. </div> <div><br/></div> <div>Now I need to sum up the two values. And I want to bind to that sum. So I extend my entity A in a partial class and add a new property, A.Sum, which sums Value1 and Value2. </div> <div><br/></div> <div>Next, I want to reflect changes made to Value1 and Value2 in the sum, to notify the interface of value changes so the sum gets recalculated - so here I run into the first problem. I have to make A.Value1 fire the change of A.Sum also. Can't do that, so I make a new property, A.Value1FireSum, which basically copies A.Value1 and adds fire change to A.Sum. Can't do that, because I get an exception saying that A.Sum is not a mapped property in the database. </div> <div><br/></div> <div>So I throw away all this entity extension thing and look into Model-Defined Functions which are said to do just that - add custom abilities to entities. I don't use function import because all I want is a simple sum, so I define the function in XML, in the model, according to MSDN samples. All fine there, but next I find out you actually have to also write the function definition in code, because it's not automatically inferred. I do that, but then again it won't work because it only works using linq syntax. </div> <div><br/></div> <div>Guys. I need a simple, basic, idiot sum, which would get updated on property changes of other values. I know I can use POCO and basically rewrite the whole Entity Framework myself in the process - but this is the most simple scenario. It's so basic I still struggle to understand why it has not been implemented in a more accessible manner. Is it so hard to have a simple extension and NOT use POCO? Simply extend the generated entity and be able to fire property changes for the extending properties? </div> <div><br/></div> <div><br/></div>Sat, 21 Nov 2009 19:51:50 Z2009-11-24T07:31:47Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/c234c7da-5989-444e-9375-672ef2d5a117http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/c234c7da-5989-444e-9375-672ef2d5a117ATT UChttp://social.msdn.microsoft.com/Profile/en-US/?user=ATT%20UChow to insert into a table which has 1-many with nullable valueI am trying to insert a record into a table (says Preferences) which has a column name ColorId, FK to a table (says Color) and it can be nullable. It's a 1-many between Color and Perferences. But I am not sure the EF allows null value on the Many End Property and if so, I do not know how to handle it.  <div>this is the CreatePreferences method i have overridden.</div> <div>public static Preferences CreatePreferences(string name, int colorId)</div> <div>{</div> <div>    Preferences p = new Preferences();</div> <div>    p.Name = name;</div> <div>    if ( colorId &gt; 0 )</div> <div>    {</div> <div>             //this is for the case the Color column is not null. This case is working fine</div> <div>             p.ColorReference.EntityKey = new EntityKey(&quot;ColorQualifiedEntitySet&quot;,&quot;EntityKeyName&quot;,colorId);</div> <div>    }</div> <div>    else</div> <div>    {</div> <div>             //this is the case of the color column is null. NOT WORKING. </div> <div> <div>             p.ColorReference.EntityKey = new EntityKey(&quot;ColorQualifiedEntitySet&quot;,&quot;EntityKeyName&quot;,null);</div> <div><br/></div> </div> <div>    }</div> <div>}</div> <div><br/></div> <div>Please help me how to insert it. Thanks in advance.</div> <div> <div><br/></div> </div>Thu, 19 Nov 2009 20:43:15 Z2009-11-24T04:56:48Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/cf891b17-b912-4dfe-9849-8496bd8021d1http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/cf891b17-b912-4dfe-9849-8496bd8021d1de2008http://social.msdn.microsoft.com/Profile/en-US/?user=de2008Reference.EntityKeyI have a Patient table<br/>I have a Test table<br/>I have a TestResult table that has references to the 1st 2 tables.<br/><br/>I try to loop thru all the tests that were done on that patient:<br/>TestResult result = new TestResult();<br/>foreach (test selected in my grid)<br/>{<br/>   result.PatientReference.EntityKey = new EntityKey(&quot;MyEntities.Patient&quot;, &quot;PatientId&quot;, patientId);<br/>   result.TestTypeReference.EntityKey = new EntityKey(&quot;MyEntities.TestType&quot;, &quot;TestTypeId&quot;, testTypeId);<br/>}<br/>context.AddToResult(result);<br/>context.SaveChanges();<br/><br/>Which works fine the first time thru the loop, however on the 2nd pass, I guess the EntityKey on the Patient already exists so what is the correct way to write this?Fri, 20 Nov 2009 23:19:11 Z2009-11-24T04:46:41Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/4dd05483-e0a7-4533-a4dd-5f344861f0abhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/4dd05483-e0a7-4533-a4dd-5f344861f0abgeoGruvenhttp://social.msdn.microsoft.com/Profile/en-US/?user=geoGruvenASP.NET Web Form slow on first request using EntitiesI have a web forms page that uses an ADO.NET Entity Model to get some data from the database using a LINQ query and builds the HTML to display in code behind C#.<br/><br/>The problem is, the first page request after more than say 30 minutes, takes about 10 seconds to render.  After that, each page renders in less than a second.<br/><br/>My guess is the database connection has to be reopened however, before I started troubleshooting this one, I thought I'd ask the group for some ponters giving that I'm new to Entities.<br/><br/>TIA,<br/>George Mon, 23 Nov 2009 23:34:35 Z2009-11-24T04:44:13Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/32265534-ac06-4676-95fe-02e6ad063540http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/32265534-ac06-4676-95fe-02e6ad063540ahagerhttp://social.msdn.microsoft.com/Profile/en-US/?user=ahagerThe primitive type 'Edm.Int32' could not be mapped within the current metadata workspace and provider., near type identifier, line 7, column 106.I am binding an EntityData Source and one of the parameters is based on the value from a dropdown.  The value of the ddl was originally an int however based on a particular use case I had to append a letter to the front of it making it a string.  My problem is that I can't seem to get the entity sql correct.  Below is the markupcode:<br/><br/><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small"><font size=2 color="#0000ff"><font size=2 color="#0000ff"> <p>&lt;</p> </font></font></span><font size=2 color="#0000ff"> <p> </p> </font></span> <p><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">asp</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">:</span></span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">EntityDataSource</span></span><span style="font-size:x-small"> </span><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">ID</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">=&quot;UnassignedCrewLeadsDataSource&quot;</span></span><span style="font-size:x-small"> </span><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">runat</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">=&quot;server&quot;</span></span><span style="font-size:x-small"> </span><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">AutoGenerateWhereClause</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">=&quot;True&quot;</span></span></p> <span style="font-size:x-small"><font size=2> <p> </p> </font></span> <p><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">CommandText</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">=&quot;SELECT value crew <p>FROM VendorCrew AS crew</p> <p>WHERE NOT EXISTS(SELECT sfvc.VendorCrew.VendorCrewId</p> <p>FROM ShipmentForwardingVendorCrew AS sfvc</p> <p>WHERE sfvc.Shipments.ShipmentId = @ShipmentId</p> <p>and sfvc.VendorCrew.VendorCrewId = crew.VendorCrewId)</p> <p>AND (crew.CompanyEntities.CompanyEntityId = cast(replace(@VendorId, 'O', '') as Edm.Int32)</p> <p>OR crew.CompanyEntities.CompanyEntityId = cast(replace(@VendorId, 'D', '') as Edm.Int32))</p> <p>AND crew.IsActive = true</p> <font size=2 color="#0000ff"><font size=2 color="#0000ff"> <p>AND crew.IsCrewLead = true&quot;</p> </font></font></span><font size=2 color="#0000ff"> <p> </p> </font></span></p> <p><span style="font-size:x-small"> </span><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">ConnectionString</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">=&quot;name=RITSNetEntities&quot;</span></span><span style="font-size:x-small"> </span><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">DefaultContainerName</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">=&quot;RITSNetEntities&quot;</span></span></p> <span style="font-size:x-small"><font size=2> <p> </p> </font></span> <p><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">Include</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">=&quot;ShipmentForwardingVendorCrew,CompanyEntities&quot;&gt;</span></span></p> <span style="font-size:x-small"><font size=2> <p> </p> </font></span> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">&lt;</span></span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">CommandParameters</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">&gt;</span></span></p> <span style="font-size:x-small"><font size=2> <p> </p> </font></span> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">&lt;</span></span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">asp</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">:</span></span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">QueryStringParameter</span></span><span style="font-size:x-small"> </span><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">Name</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">=&quot;ShipmentId&quot;</span></span><span style="font-size:x-small"> </span><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">QueryStringField</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">=&quot;10&quot;</span></span><span style="font-size:x-small"> </span><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">Type</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">=&quot;Int32&quot;</span></span><span style="font-size:x-small"> </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">/&gt;</span></span></p> <span style="font-size:x-small"><font size=2> <p> </p> </font></span> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">&lt;</span></span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">asp</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">:</span></span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">ControlParameter</span></span><span style="font-size:x-small"> </span><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">ControlID</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">=&quot;ddlODAgent&quot;</span></span><span style="font-size:x-small"> </span><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">Name</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">=&quot;VendorId&quot;</span></span><span style="font-size:x-small"> </span><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">PropertyName</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">=&quot;SelectedValue&quot;</span></span></p> <span style="font-size:x-small"><font size=2> <p> </p> </font></span> <p><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">Type</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">=&quot;String&quot;</span></span><span style="font-size:x-small"> </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">/&gt;</span></span></p> <span style="font-size:x-small"><font size=2> <p> </p> </font></span> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">&lt;/</span></span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">CommandParameters</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">&gt;</span></span></p> <span style="font-size:x-small"><font size=2> <p> </p> </font></span> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">&lt;/</span></span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">asp</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">:</span></span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">EntityDataSource</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">&gt;</span></span></p><hr class="sig">AdamFri, 20 Nov 2009 02:13:20 Z2009-11-24T00:29:33Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/47ee752c-8df0-49ec-8002-c93f30e6848bhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/47ee752c-8df0-49ec-8002-c93f30e6848bsnorlakshttp://social.msdn.microsoft.com/Profile/en-US/?user=snorlakscreate new table runtimeHello,<br/> <br/> I would like to know if its possible to create new table dynamically from the program. And then when new one is created based on known schema list or tables from the database with the same schema and choose one as a linq mapped object. <br/> <br/> thanks for helpMon, 23 Nov 2009 20:10:42 Z2009-11-23T22:13:32Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/c88aa9fb-f969-42f7-967d-2b1435cecb1chttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/c88aa9fb-f969-42f7-967d-2b1435cecb1cGiulianoGrohttp://social.msdn.microsoft.com/Profile/en-US/?user=GiulianoGroFunctionImport and Reference Properties<p>I'm loading a set of a entites using a stored procedure.<br/>Now the loaded entites have the navigation property set to null and would like to assign the manually in this way :<br/></p> <pre lang="x-c#"> List&lt;Assignment&gt; assignments = _model.AssignmentsByProjectId(ProjectId).ToList(); foreach (Assignment a in assignments) a.Resource = _model.Resource.First(e =&gt; e.ResourceId == Convert.ToInt32(a.ResourceReference.EntityKey.EntityKeyValues[0].Value)); </pre> The problem is that event he ResourceReference property is null, so i have no Foreign Key reference...<br/>Any Help ?! THXWed, 18 Nov 2009 09:12:56 Z2009-11-23T21:03:29Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/579bd08e-4010-47e2-925c-fa2d05b9a96fhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/579bd08e-4010-47e2-925c-fa2d05b9a96fJCC74http://social.msdn.microsoft.com/Profile/en-US/?user=JCC74How to separate generated edmx entities from Context methods in different projects?Hi, <div>In my architecture (VS2008, Asp.Net 3.5 project, wcf project, and some dao project, dto, common libraries), i'd like to separate edmx generated class.</div> <div>There's no site that could solve my issue, solutions iv've found is implementing POCO objects and mapper. I'd like The VS2008 edmx code generator to put the DTO in on common project and the DAO in an other one, not referenced in the UI project but referenced in my WCF services project.</div> <div>My goal is implementing a dynamic proxy in the UI layer with unity container -&gt; I need to externalise services contracts and entities definitions in a common project-&gt; but does not seem to be possible with edmx file as is.</div> <div>Is that possible and How? </div> <div>Thanx'</div>Sun, 25 Oct 2009 17:12:09 Z2009-11-24T08:58:17Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/095745fe-dcf0-4142-b684-b7e4a1ab59f0http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/095745fe-dcf0-4142-b684-b7e4a1ab59f0Amit Kumar Mimeohttp://social.msdn.microsoft.com/Profile/en-US/?user=Amit%20Kumar%20MimeoWHERE IN clause?<p align=left>Hi, we just started experimenting with LINQ to Entities and we're looking to be able to accomplish the same functionality as a WHERE IN statement in SQL because we have a single field that we want to compare to multiple values. For example:</p> <p align=left> </p> <p align=left> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Block</span></div> <p align=left>SELECT *</p> <p align=left>FROM Foo</p> <p align=left>WHERE blah IN (1, 3, 5, 7)</p> <p align=left> </p></div></div> <p align=left> </p> <p>Currently the list of values we wanted to compare to is in a List&lt;T&gt;. We tried the following LINQ query, but get an error:</p> <p align=left> </p> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Block</span></div> <p align=left>List&lt;int&gt; statusesToFind = ...;</p> <p align=left> </p> <p align=left>var foos = from foo in myEntities.Foos</p> <p align=left>           join status in (from statusToFind in statusesToFind</p> <p align=left>                           select statusToFind) on foo.Status equals status</p> <p align=left>           select foo;</p> <p align=left> </p></div></div> <p align=left><strong></strong> </p> <p align=left>The error we received was:</p> <p align=left>&quot;Unable to create a constant value of type 'System.Collections.Generic.IEnumerable`1'. Only primitive types (for instance Int32, String and Guid) are supported in this context.&quot;</p> <p> </p> <p align=left>We also tried this query:</p> <p align=left> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Block</span></div> <p align=left>List&lt;int&gt; statusesToFind = ...;</p> <p align=left> </p> <p align=left>var foos = from foo in myEntities.Foos</p> <p align=left>           where statusesToFind.Contains(foo.Status)</p> <p align=left>           select foo;</p> <p align=left> </p></div></div> <p align=left> </p> <p></p> <p align=left>This version seems more along the lines of what we're trying to say literally, but it complains about not being able to translate the Contains method to something usable in the query, which I suppose makes sense.</p> <p align=left> </p> <p align=left>Anyway, does anyone have any hints on how to accomplish the equivalent of a WHERE IN?</p> <p align=left> </p> <p align=left>TIA,</p> <p align=left>Amit</p>Fri, 11 Jan 2008 23:39:03 Z2009-11-24T00:41:40Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/80ff7239-179b-446c-8304-b927b520af77http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/80ff7239-179b-446c-8304-b927b520af77Riti07http://social.msdn.microsoft.com/Profile/en-US/?user=Riti07I am getting the error ????Please helphello all,i am getting an error in my mvc application please help me.<br/> <br/> The error I am getting is following:<br/> <br/> The entity or complex type 'Northwind Model.Products' cannot be constructed in a LINQ to Entities query.<br/> <br/> i am getting this error in my class file :<br/> public IList&lt;Products&gt; fetchAllFeaturedProducts()<br/>         {<br/> <br/> <br/>             using (NorthwindEntities modelObject = new NorthwindEntities())<br/>             {<br/> <br/>                 IQueryable&lt;Products&gt; currentFeaturedProducts = (from currentFeaturs in modelObject.Products<br/>                                                                 select new Products ()<br/>                                                                 {<br/>                                                                     //image_name = currentFeaturs.image_name,<br/>                                                                     ProductName = currentFeaturs.ProductName,<br/>                                                                     UnitPrice = currentFeaturs.UnitPrice.Value<br/>                                                                 }<br/> <br/>                                                                           ).AsQueryable ();<br/> <br/> <br/> <br/>                 return currentFeaturedProducts.ToList();<br/>             }<br/> <br/> <br/> <br/>         }<br/> whichj i am calling in my controller class:<br/> <br/>  public ActionResult showFeaturedProducts(string sidx, string sord, int page, int rows)<br/>         {<br/>             return Content(JsonHelper.JsonForJqgrid(getFeaturedProducts(sidx, sord, page, rows), rows, 0, page), &quot;application/json&quot;);<br/>         }<br/> <br/>         //code to fetch shopping cart with paging<br/>         public DataTable getFeaturedProducts(string sidx, string sord, int page, int pageSize)<br/>         {<br/> <br/>             productrepository objProductRep = new productrepository();<br/>             DataTable tblFeaturedProducts = new DataTable();<br/>             DataRow catRow;<br/>             //tblFeaturedProducts.Columns.Add(&quot;imagename&quot;, Type.GetType(&quot;System.String&quot;));<br/>             tblFeaturedProducts.Columns.Add(&quot;productName&quot;, Type.GetType(&quot;System.String&quot;));<br/>             tblFeaturedProducts.Columns.Add(&quot;productPrice&quot;, Type.GetType(&quot;System.String&quot;));<br/>             IList&lt;Products&gt; allFeaturedProducts = objProductRep.fetchAllFeaturedProducts();<br/> <br/> <br/> <br/> <br/> <br/>             foreach (Products  oneFeaturedProduct in allFeaturedProducts)<br/>             {<br/>                 catRow = tblFeaturedProducts.NewRow();<br/>                 //catRow[&quot;imagename&quot;] = oneFeaturedProduct.image_name.ToString();<br/>                 catRow[&quot;productName&quot;] = oneFeaturedProduct.ProductName.ToString();<br/>                 catRow[&quot;productPrice&quot;] = Convert.ToDouble(oneFeaturedProduct.UnitPrice.ToString());<br/>                 tblFeaturedProducts.Rows.Add(catRow);<br/> <br/>             }<br/>             return tblFeaturedProducts;<br/>         }<br/> <br/> and this I am passing to the jquery grid<br/>  jQuery(document).ready(function() {<br/> <br/>     jQuery(&quot;#editgrid&quot;).jqGrid({<br/>             url: '/Home/showFeaturedProducts/',<br/>             datatype: 'json',<br/>             mtype: 'GET',<br/>             colNames: [ 'Name', &quot;UnitPrice&quot;],<br/>             colModel: [<br/> //          { name: 'Id', index: 'Id', width: 40, align: 'left' },<br/>           { name: 'Name', index: 'Name', width: 40, align: 'left' },<br/> //          { name: 'QuantityPerUnit', index: 'QuantityPerUnit', width: 200, align: 'left' },<br/>           { name: 'UnitPrice', index: 'UnitPrice', width: 200, align: 'left'}],<br/>             rowNum: 10,<br/>             rowList: [5, 10, 20, 50],<br/>             sortname: 'Id',<br/>             sortorder: &quot;desc&quot;,<br/>             viewrecords: true,<br/>             caption: 'My first grid'<br/> <br/> <br/>         });<br/>     }); <br/> <br/> <br/> Please help me what shall I do and I am using the Entity data model as the model of my database<br/> <br/> <br/> Please help me<br/> <br/> Thanks in advance<br/> RitiMon, 23 Nov 2009 11:50:39 Z2009-11-23T18:14:39Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/d739ec86-98df-42a6-b8da-3a52b2844837http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/d739ec86-98df-42a6-b8da-3a52b2844837havegot2beonlinehttp://social.msdn.microsoft.com/Profile/en-US/?user=havegot2beonlineUpdateException (cardinality constraints) when adding to 1:0..1 relation<p>I have the following simple model:<br/><a href="http://img504.imageshack.us/img504/2434/capturewn.png">http://img504.imageshack.us/img504/2434/capturewn.png</a><br/><br/>I want to add a newly created single ObservedFileMeta and several newly created ObservedFileParts to an ObservedFile which is already in the database in this case. <br/>Whjen I try to run the following code:</p> <pre lang="x-c#"> Context.AddToObservedFileMetaSet(meta); Context.Attach(file); file.Meta = meta; foreach (ObservedFilePart part in parts) { Context.AddToObservedFilePartSet(part); file.Parts.Add(part); } Context.SaveChanges();</pre> I get an UpdateException:<br/> <pre>System.Data.UpdateException was unhandled Message=&quot;A relationship is being added or deleted from an AssociationSet 'ObservedFileObservedFileMeta'. With cardinality constraints, a corresponding 'ObservedFileMeta' must also be added or deleted.&quot; <br/></pre> <br/>While searching the web I found several people encountering a similiar problem but only when trying to delete entities.<br/><br/>I debugged to check if the EntityStates of the objects seem right:<br/>file has &quot;Unmodified&quot; while meta and the parts have &quot;Added&quot; as their EntityState.<br/><br/>What am I doing wrong or need to make sure?<br/><br/>Thank you for your help.<br/>Fri, 20 Nov 2009 21:15:42 Z2009-11-24T05:32:17Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/269ed01c-2fca-4d7f-8d69-3a86fe49b06ehttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/269ed01c-2fca-4d7f-8d69-3a86fe49b06eOlaf Rabbachinhttp://social.msdn.microsoft.com/Profile/en-US/?user=Olaf%20RabbachinPick-list: relationship not mapped correctly?Hi folks,<br/> <br/> I have two tables, i.e.:<br/> <ul> <li>tbl_Contacts (mapped as entity &quot;Contact&quot;) </li> <li>tbl_Titles (mapped as entity &quot;Title&quot;) </li> </ul> There is a 1:n relationship between <em>Title</em> and <em>Contact</em> . The PKs/FKs are GUIDs (RowGuid = True). That is, each Contact record needs to have a Title-reference (FK set).<br/> When querying the DB for contacts, i.e. ...<br/> <br/> <pre lang=x-vbnet>Dim results = _ From r In _db.Contacts _ Order By r.LastName, r.FirstName _ Select r </pre> <br/> ... the Title-property for the contact-record will always be empty (null/nothing). If I change the above to ...<br/> <br/> <pre lang=x-vbnet>Dim results = _ From r In _db.Contacts.Include(&quot;Title&quot;) _ Order By r.LastName, r.FirstName _ Select r </pre> <br/> ... the Title-property will be available. Julia Lerman's &quot;Programming Entity Framework&quot; tells me that, actually, the first query should return what the second does.<br/> <br/> What am I doing wrong here?<hr class="sig">Cheers,<br/>OlafMon, 23 Nov 2009 11:02:56 Z2009-11-23T15:25:46Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/5854b93c-64a7-4c4b-9a5a-2140e974a338http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/5854b93c-64a7-4c4b-9a5a-2140e974a338pdxJaxonhttp://social.msdn.microsoft.com/Profile/en-US/?user=pdxJaxonAnother Question About Mapping Entities to VIEWSWe ran into the issue today with using VIEWS to map your entities to (All Non Nullable Columns are assumed to be part of the key). For various reasons (of which I dont care to get into), we need to use Views as opposed to mapping directly to tables. Is there any update from MSFT that will allow us to map to views as if they were tables? If not then I would say this is a HUGE OVERSIGHT on Microsoft's part and it really makes the EF as an ORM worthless to us. I really need a solution quickly on this. Cheers, Greg Jackson Data Architect Ethics Point <hr class="sig">Gregory A JacksonTue, 17 Nov 2009 21:31:28 Z2009-11-25T03:32:54Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/db9474f4-08be-4bef-aa21-df4f221b2011http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/db9474f4-08be-4bef-aa21-df4f221b2011Bob Bedellhttp://social.msdn.microsoft.com/Profile/en-US/?user=Bob%20BedellConnectionstring??Hello,<br/><br/>I have the three, stand-alone medata files (DataModel.csdl, DataModel.msl, DataModel.ssdl) in a library assembly named 'DataModel' each files Build Action property set to Embedded Resource. I have a client project that references this assembly.<br/><br/>I've tried a million different App.Config connection strings, and I can't seem to load the metadata files. I either get an invalid path or an invalid assembly name exception.<br/><br/>I'm trying something along the lines of:<br/><br/> connectionString=&quot;Metadata=<br/>         res://DataModel,1.0.0.0,neutral,null/DataModel.csdl| <br/>         res://DataModel,1.0.0.0,neutral,null/DataModel.ssdl| <br/>         res://DataModel,1.0.0.0,neutral,null/DataModel.msl;<br/><br/>This one gives me:<br/><br/>Exception: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)<br/><br/>The assembly DataModel.dll is in bin/debug in the clint app. I've tried a bunch of relative paths. When I llok at the assembly in reflector, the resources are named DataModel.DataModel.csdl, etc. so I tried that too.<br/><br/>Any help much appreciated.<br/><br/>Bob<br/>Sat, 21 Nov 2009 23:28:19 Z2009-11-23T05:55:58Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/5c145ff3-711b-49c0-bb68-a58167a300cdhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/5c145ff3-711b-49c0-bb68-a58167a300cdMcQwertyhttp://social.msdn.microsoft.com/Profile/en-US/?user=McQwertyAt least one of the key properties of AssociationSet <SetName> must be mapped to all the key properties error using one-to-many relationship with link table in Entity FrameworkHi all, this is my first post so please be gentle...<br/> <br/> I am working with the entity framework and just can't understand why I am getting the following error;<br/> <br/> At least one of the key properties of AssociationSet ServiceOrder_TaxRate must be mapped to all the key properties (LinkTable_ServiceOrder_TaxRate.ServiceOrderID, LinkTable_ServiceOrder_TaxRate.TaxRateID) of table LinkTable_ServiceOrder_TaxRate.<br/> <br/> My table 'LinkTable_ServiceOrder_TaxRate' is just a link table with two columns, <br/> ServiceOrderID<br/> TaxRateID<br/> <br/> I created my entity diagram from the SQL DB and VisualStudio automatically created the associations and hid the link table.<br/> <br/> As you would expect, the associations were created as many-to-many and if left in this state there are no errors.<br/> But I want this association to me many-to-one (Many Service Orders can have one Tax Rate, One Tax Rate can have many ServiceOrders)<br/> <br/> When I change the association with the tax rate end set to '1 (One)' the above error occurs.<br/> <br/> Double clicking on the error takes me to the Mapping Details but the appear correct to me:<br/> One association that maps to table LinkTable_ServiceOrder_TaxRate<br/> SeriveOrder.ID -&gt; ServiceOrderID<br/> TaxRate.ID -&gt; TaxRateID<br/> <br/> Now, I know I could just add a column to the Service Order table to hold the FK of the requred Tax Rate, but for reporting and consistency I want to use seperate link tables for all of my associations.<br/> Also I don't see why the above approach doesn't work.<br/> <br/> Please could someone explain how to use LinkTables with associations other than many-to-many?<br/> <br/> Thanks in advance!<br/> Matt<br/>Mon, 16 Nov 2009 17:03:27 Z2009-11-25T03:29:25Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/bf9aa0c0-dcfd-4146-a8f5-fa1293f6a89bhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/bf9aa0c0-dcfd-4146-a8f5-fa1293f6a89bJay in Bellevuehttp://social.msdn.microsoft.com/Profile/en-US/?user=Jay%20in%20BellevueHow can I convert a type so I can compare two columns with different types in joins?<p>I'm relatively new to Linq to Entity framework, and I'm not quite yet familiar with all the limitations and gotya's of LINQ to entity queries. The problem I'm having is this:</p> <div style="background-color:white;color:black"> <pre><span style="color:blue">var</span> variable = <span style="color:blue">from</span> A <span style="color:blue">in</span> TableA <span style="color:blue">join</span> B <span style="color:blue">in</span> TableB <span style="color:blue">on</span> A.intType <span style="color:blue">equals</span> B.stringType <span style="color:blue">select</span> A.someProperty; </pre> </div> Now, you can't use CLR's common type conversion methods like Int32.Parse(B.stringType) up there, because this is considered arbitrary client function and Linq to Entity does not know how to turn Int32.Parse function into stored expression. And it is not apparent to me how you can convert the string type to int for comparison above.<br/><br/>I've looked at some references to EntityFunctions and SQLfunctions but they don't seem to help in this situation.<br/>Sat, 14 Nov 2009 09:24:26 Z2009-11-23T20:36:17Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/9db6f1fd-5420-4933-a714-c3dd94aea157http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/9db6f1fd-5420-4933-a714-c3dd94aea157Bob Bedellhttp://social.msdn.microsoft.com/Profile/en-US/?user=Bob%20BedellEntityFramework POCO Code GeneratorHello,<br/><br/>I'm playing around with some of the Feature CTP Walkthroughs from the ADO.NET team blog. I have VS Beta 2 and the Entity Framework Feature CTP 2 installed. I was working with the POCO Templates for Entity Framework walkthrough.<br/><br/>First, I see that this and the POCO Template walkthrough targets Beta 1 and CPT 1. I was trying to implement it with Beta 2, but the EntityFramework POCO Code Generator T4 template isn't listed in my project item templates. I only have the ADO.NET Self-Tracking Entity Generator template.<br/><br/>Was the POCO template removed fromm Beta2/CPT2??? Or should I have it somewhere??<br/><br/>Thanks for any help.<br/><br/>BobMon, 23 Nov 2009 00:14:43 Z2009-11-23T20:36:47Z