How can one prevent Entity Framework from calling the update stored procedure, even though nothing should have changed?
I have an entity A that has a link 开发者_运维问答to an entity B through the property prop
. The relationship is a 1-n relationship (foreign key in the table corresponding to A).
The relationship is bidirectional (B has a property that lists all A through which it is related with prop
).
We have been able to determine that, in that case, the saveChanges
method call was calling the update
stored procedure for the B table, even though none of the columns in the table had changed.
Is that normal/expected? How should someone do to avoid it?
Edit: I have checked the state flags for both the "A" and "B" objects, and as expected, the "B" object is in the "unchanged" state.
Edit 2: Thanks to everyone for telling me about update flags (I didn't know how to access that information) - which has led me to find that link, describing my problem in more detail:
Entity Framework 4 Entity with EntityState of Unchanged firing update
There is a hotfix mentioned on http://support.microsoft.com/kb/2390624
Though that support issue's description is only loosely related to the behaviour I describe, the provided hotfix also solves my issue.
That issue has been publicly fixed on in release 4.5 of the .NET framework. For the .NET 4.0 framework, I would expect that using EF 6.0 (currently in beta) would also solve the issue.
精彩评论