When I try to use these two features together, I get a compilation error on my model (note, I’ve renamed the entity for my _CT table “ContentHistory” and my SL4 Unit Test project is called “DomainServices.UnitTest”:
Error 39 Property 'DomainServices.Web.ContentHistory.C___seqval' is marked as a key
property and is of Type 'System.Byte[]', which is not a supported type for a key member.
DomainServices.UnitTests
Has anyone here gotten CDC and EF4 to play nicely together?
Okay, here’s what I’ve done to work around this issue. I made sure that every table that I want to enable CDC on has a
LastModifiedcolumn of typedatetime. Then, I added a key (from an EF point of view) consisting of theLastModifiedcolumn and the__$operationcolumn. I figure this is “probably unique” (which is somewhat frightening, but probably okay). My reasoning is that theLastModifiedis accurate to about 3ms, so the only time that I’ll (realistically) get 2 rows in my CDC table with the sameLastModifiedis on an update; but, on an update those two rows will have different__$operationvalues (a 3 and a 4). So, compounding those together makes at least a modicum of sense for a key. I am not a big fan of this, and wish that EF4 would support tables with no keys. If anyone has a suggestion, please please let me know.