Entity Framework 4 和 SQL Server 2008 R2 更改数据捕获不能很好地协同工作
当我尝试一起使用这两个功能时,我的模型出现编译错误(请注意,我已将 _CT 表的实体重命名为“ContentHistory”,并且我的 SL4 单元测试项目称为“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
: CDC 和 EF4 可以很好地协同工作吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,这就是我为解决此问题所做的工作。我确保要启用 CDC 的每个表都有一个
LastModified
类型为datetime
的列。然后,我添加了一个由LastModified
列和__$operation
列组成的键(从 EF 的角度来看)。我认为这“可能是独一无二的”(这有点可怕,但可能还好)。我的推理是LastModified
精确到大约 3ms,因此我(实际上)在 CDC 表中获得具有相同LastModified
的 2 行的唯一时间是更新;但是,在更新时,这两行将具有不同的__$operation
值(3 和 4)。因此,将这些组合在一起至少对密钥有一定的意义。我不太喜欢这个,并希望 EF4 支持没有键的表。如果有人有建议,请告诉我。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 typedatetime
. Then, I added a key (from an EF point of view) consisting of theLastModified
column and the__$operation
column. I figure this is "probably unique" (which is somewhat frightening, but probably okay). My reasoning is that theLastModified
is accurate to about 3ms, so the only time that I'll (realistically) get 2 rows in my CDC table with the sameLastModified
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.