LINQ to SQL's GetOriginalEntityState 不包含 EntitySet or Entity Ref Data for Related Entities

问题描述:

After populating a LINQ to SQL entity's associations (EntitySet, EntityRef or both) by eager loading, the GetOriginalEntityState(modifiedmember) object's Entity Set and Entity Ref fields are empty.


As an example using Northwind, the Table<TEntity>.GetOriginalEntityState(modifiedMember) method applied to the DataContext.Customers entity returns Customer objects with Customer.Orders.Count = 0. The Table<TEntity>.GetModifiedMembers(ch => ch.ModifiedEntities) method has correct Customer.Orders.Count values so the change tracker interprets the Order objects as added and generates spurious T-SQL statements to add new Orders.

A detailed description of the bug and screen captures of test harnesses, including the harness for this report, is at GetOriginalEntityState() Loses EntitySet/EntityRef Data (http://oakleafblog.blogspot.com/2007/10/getoriginalentitystate-loses.html).

The problem might be a side-effect of or responsible for the issue described in bug report 295402: Incorrect Update Behavior - Attaching an Entity after Calling a Relationship Property of 8/27/2007 (https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=295402). This report was closed as [to be] Fixed on 9/5/2007. For more details on that bug report and a sample of its affect on LINQ to SQL applications, see the "Fighting the Attached Associated Objects Bug" of LINQ to SQL and Entity Framework XML Serialization Issues with WCF - Part 1 of 10/9/2007. However, it needs independent investigation.

This bug is NOT believed to relate to my Feedback 294781, LINQ to SQL Objects Eager Loaded with LoadOptions Aren't Recognized by Object Tracker (https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=294781).

A test harness demonstrating the problem is attached. The test harness requires a local SQL Server Express instance (not a file) of Northwind. (Change the connection string in app.config to suit your setup.) Run the project, make a minor change to one of the Customer.CompanyName (e.g., Market -> Mart) and an Order.EmployeeID (e.g., 6 to 7) and click the Submit button to display the message box. 


评论:

Microsoft 在 2008/11/21 1:39 发送
Hello Roger,

As Matt explains this is by design. Informatoin on the original graph is maintaned in the object tracker, but in order to return entities with entity refs and sets we would need to pull everything that is reachable. The information on modified members comes from the current graph, which actually exists in memory independently of the object tracker.

We have also verified that no spurious inserts are issued when SubmitChanges() is invoked after calling GetOriginalEntityState().

Thanks for reporting this.
The LINQ to SQL Team 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值