EF4 是否始终为所有相关实体生成更新语句,即使实际上只有一个实体发生更改?
.NET 4,EF 4
我有两个相关实体,Order 和 OrderLine。 Order 包含(引用)OrderLine。
Public Class Order
Public Property OrderLine
End Class
数据库中的每个实体都有一张表(订单表、订单行表)。每个表都有一个时间戳列,EF4 模型为每个列的时间戳表设置了 ConcurrencyMode = Fix。
我对订单进行了更改,但保持订单行不变。当我调用 SaveChanges 时,EF4 似乎会生成 OrderLine 的更新查询,即使其上没有任何更改。最终结果是,数据库响应 EF4 更新命令而更新了 OrderLine 的时间戳,但没有更新任何其他内容,因为 OrderLine 上没有任何更改。
这是 EF4 应该处理这个问题的方式吗?如果是,为什么?
.NET 4, EF 4
I have two related entities, Order and OrderLine. Order contains (has a reference to) OrderLine.
Public Class Order
Public Property OrderLine
End Class
There is one table for each entity in the database (order table, orderline table). Each table has a timestamp column and the EF4 model is set up with ConcurrencyMode = Fixed for the timestamp table of each column.
I make a change to the Order, but leave the OrderLine unchanged. When I call SaveChanges, it appears that EF4 generates an update query for the OrderLine even though nothing has changed on it. The end result is that the timestamp for the OrderLine gets updated by the database in response to the EF4 Update command, but nothing else is updated because nothing was changed on the OrderLine.
Is this the way EF4 is supposed to handle this? If it is, why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 EF4 中的一个已知错误,您可以尝试联系 MS 获取修补程序。您可以在保存之前分离未修改的实体,然后保存然后重新附加实体作为解决方法。据我所知,它似乎已在 .NET Framework 4.5 的开发者预览版中修复,但尚未获得生产使用许可。
This is a known bug in EF4, you can try to contact MS for a hotfix. You can detach unmodified entities before saving, save, and then reattach the entities as a workaround. As far as I have been able to tell, it appears fixed in the Developer Preview of .NET Framework 4.5, but that is not licensed for production use.