tag:blogger.com,1999:blog-9567658.post3987356750818610736..comments2023-12-08T05:18:40.614-07:00Comments on Luis Rocha's Blog: Creating Composite Keys using Code First with Entity FrameworkLuis Rochahttp://www.blogger.com/profile/08940711209780493058noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-9567658.post-82940937285098538312013-07-05T00:31:49.094-06:002013-07-05T00:31:49.094-06:00Nice write up! In my opinion the fluent approach w...Nice write up! In my opinion the fluent approach wins, since this enables you to free the domain (the POCO classes) from EF dependency polution (PI).Morten Hoffmann Sørensenhttp://www.strongminds.dknoreply@blogger.comtag:blogger.com,1999:blog-9567658.post-51697819610921268012013-02-05T16:36:27.449-07:002013-02-05T16:36:27.449-07:00Hi, I noticed that when I use composite keys, no I...Hi, I noticed that when I use composite keys, no Ids are generated by EF. Is there a way to tell EF to generate the keys?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9567658.post-90972008712438373302011-12-19T23:35:23.614-07:002011-12-19T23:35:23.614-07:00Bob,
Are you trying to find an entity object by t...Bob,<br /><br />Are you trying to find an entity object by the primary key? If so, the DbSet Find takes a “params object[]” as it’s parameter so if you have composite keys you just specify the values for each key property in the order you defined them. In the example above, it would be:<br /><br />var rec = db.PlaylistTrack.Find(nPlayListId, nTrackId);<br /><br />I hope this helps. Thanks,<br />LuisLuis Rochahttps://www.blogger.com/profile/08940711209780493058noreply@blogger.comtag:blogger.com,1999:blog-9567658.post-29174710479339672432011-12-16T07:56:33.829-07:002011-12-16T07:56:33.829-07:00I tried both methods and then tried the equivalent...I tried both methods and then tried the equivalent of: <br /><br /><i>var rec = db.PlaylistTrack.Find(new { nPlayListId, nTrackId });</i><br /><br />but it throws an ArgumentException: "The number of primary key values passed must match number of primary key values defined on the entity.<br />Parameter name: keyValues"<br /><br />Any ideas?Bobhttps://www.blogger.com/profile/09157624911308687897noreply@blogger.comtag:blogger.com,1999:blog-9567658.post-53299807282427688932011-06-27T04:17:44.030-06:002011-06-27T04:17:44.030-06:00Hi, Thank you for your excellent article. I google...Hi, Thank you for your excellent article. I googled blogs as well as forums, but they are not providing clear examples like yours... <a href="http://www.webhostings.in" rel="nofollow">webhosting</a>web hostinghttp://www.webhostings.innoreply@blogger.comtag:blogger.com,1999:blog-9567658.post-88841989799942697422011-06-20T20:38:25.319-06:002011-06-20T20:38:25.319-06:00Your comment about having the composite primary ke...Your comment about having the composite primary key defined in the mapping class appear in the same order as the database table is right on. I had been tripped up with this until I stumbled upon this article. Much thanks!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9567658.post-7325749275071571982011-05-07T15:14:46.335-06:002011-05-07T15:14:46.335-06:00Thank you for your excellent article. I googled bl...Thank you for your excellent article. I googled blogs as well as forums, but they are not providing clear examples like yours.<br />johnaspnetAnonymousnoreply@blogger.com