简体   繁体   中英

Why DbSet.Local performs Detect Changes automatically?

In my latest question it was pointed out that DbSet.Local automatically performs Detect Changes See the question: Why is referencing DbSet.Local slow in a loop?

In the answers-comments this link was posted https://msdn.microsoft.com/en-us/data/jj556205.aspx which lists the properties

By default, the Entity Framework performs Detect Changes automatically when the following methods are called:

  • DbSet.Find
  • DbSet.Local
  • DbSet.Remove
  • DbSet.Add
  • DbSet.Attach
  • DbContext.SaveChanges
  • DbContext.GetValidationErrors
  • DbContext.Entry
  • DbChangeTracker.Entries

There are two properties in the list which I'm not sure why detect changes is necessary: find and local I guess it might be needed as there can be more instances of DbSet and changes would not get synced otherwise.

What's the purpose of detect changes upon find and local?

From the link which was posted in the comments I've found an answer. If DbSet.Local or DbSet.Find would not detect changes, you won't get entities which are in the added state (not yet committed to DB)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM