-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DbSet.Local does not automatically call DetectChanges #14001
Comments
Note for triage: the difference from EF6 here is that @fiseni EF needs DetectChanges to be called to know that the change to the navigation property has been made. For example: order.OrderLines.Remove(order.OrderLines.FirstOrDefault());
context.ChangeTracker.DetectChanges(); |
Thank you @ajcvickers . I might be reasoning wrong, but I can't see the benefit of having these actions decoupled. Now we'll have to call DetectChanges anytime we want to use DbSet.Local. Most of the time, if not always, they'll be paired anyway. |
@fiseni DetectChanges can be expensive, and depending on how Local is being used it may or may not be needed. |
Triage: we will make calling .Local call DetectChanges automatically. (Unless, of course, automatic DetectChanges is switched off.) |
* Fixes #15294 - BoolToStringConverter should not check if falseValue or trueValue is empty * Fixes #15266 - Small typo in resource file * Fixes #14037 - XML comments for DbContext.Attach unclear * Fixes #14001 - DbSet.Local does not automatically call DetectChanges * Fixes #13210 - WithExtension suggests that 'this' is updated, as well as returning 'this'
* Fixes #15294 - BoolToStringConverter should not check if falseValue or trueValue is empty * Fixes #15266 - Small typo in resource file * Fixes #14037 - XML comments for DbContext.Attach unclear * Fixes #14001 - DbSet.Local does not automatically call DetectChanges * Fixes #13210 - WithExtension suggests that 'this' is updated, as well as returning 'this'
* Fixes #15294 - BoolToStringConverter should not check if falseValue or trueValue is empty * Fixes #15266 - Small typo in resource file * Fixes #14037 - XML comments for DbContext.Attach unclear * Fixes #14001 - DbSet.Local does not automatically call DetectChanges * Fixes #13210 - WithExtension suggests that 'this' is updated, as well as returning 'this'
* Fixes #15294 - BoolToStringConverter should not check if falseValue or trueValue is empty * Fixes #15266 - Small typo in resource file * Fixes #14037 - XML comments for DbContext.Attach unclear * Fixes #14001 - DbSet.Local does not automatically call DetectChanges * Fixes #13210 - WithExtension suggests that 'this' is updated, as well as returning 'this'
* Fixes #15294 - BoolToStringConverter should not check if falseValue or trueValue is empty * Fixes #15266 - Small typo in resource file * Fixes #14037 - XML comments for DbContext.Attach unclear * Fixes #14001 - DbSet.Local does not automatically call DetectChanges * Fixes #13210 - WithExtension suggests that 'this' is updated, as well as returning 'this'
I believe my 2.2 -> 3.1 code is currently suffering a performance degredation approximating x7500 by this coupling, of 24 seconds to 50 minutes, and it's all been isolated to accessing local context. |
That's a huge difference. Did you try disabling DetectChanges to ensure that this coupling is causing the issue?
Weird, EF6 always kept DbSet.Local in sync and never experienced such low performances. |
DbSet.Local usually is utilized through ToBindingList() and ToObservableCollection(). Since, the changes where not updated automatically, the two-way databinding was not working as expected. That's the reason of raising this issue. Of course your use case might be totally different. Now when I see the internal implementation, if you're working directly with DbSet.Local and accessing it frequently, that would be a problem. |
I did, actually.
Coworker figured out an extension method that made it not too major of a
code change to work around it (disable, try return dbset.local, finally set
change tracking to the initial state)
Dropped back to within expected tolerances without further modification
…On Wed, Jul 8, 2020, 4:22 PM Fati Iseni ***@***.***> wrote:
DbSet.Local usually is utilized through ToBindingList() and
ToObservableCollection(). Since, the changes where not updated
automatically, the two-way databinding was not working as expected. That's
the reason of raising this issue.
Of course your use case might be totally different. Now when I see the
internal implementation, if you're working directly with DbSet.Local and
accessing it frequently, that would be a problem.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#14001 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAYR7G6CURD6TTCDIQJDQT3R2TIQFANCNFSM4GF7WLDA>
.
|
If child is removed from parent's collection, the child's FK is not null when accessing through Set<>.Local property. If we analyze further, we see that CurrentValue is set to null, and I assume it returns the OriginalValue (not null). I'm not sure if this is done by design on EF Core (EF6 has correct behavior). The relationship is nullable.
The text was updated successfully, but these errors were encountered: