Entity Framework 4 和 SQL Server 2008 R2 更改数据捕获不能很好地协同工作

发布于 2024-09-19 06:09:27 字数 369 浏览 2 评论 0原文

当我尝试一起使用这两个功能时,我的模型出现编译错误(请注意,我已将 _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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

朮生 2024-09-26 06:09:28

好的,这就是我为解决此问题所做的工作。我确保要启用 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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文