问题描述:
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
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