3

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?

David Moye
  • 701
  • 4
  • 13
  • Okay, so here's the way this breaks down. The CDC tables in the database have no primary keys. As a result, EF4 infers the key. It's not making good choices. For that matter, I'm not sure what a good choice is since binary(10) and varbinary(128) are not valid types for key columns in EF4. – David Moye Sep 16 '10 at 19:28
  • You're just trying to use EF to *read* the CDC tables, correct? – Steve Michelotti Sep 20 '10 at 02:35

1 Answers1

0

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 LastModified column of type datetime. Then, I added a key (from an EF point of view) consisting of the LastModified column and the __$operation column. I figure this is "probably unique" (which is somewhat frightening, but probably okay). My reasoning is that the LastModified is accurate to about 3ms, so the only time that I'll (realistically) get 2 rows in my CDC table with the same LastModified is on an update; but, on an update those two rows will have different __$operation values (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.

David Moye
  • 701
  • 4
  • 13
  • To reiterate, I don't like this answer. It's just what I'm doing to "get by." If there's a better answer out there, someone please chime in :) – David Moye Sep 21 '10 at 18:51