Does SaveChanges actually call DetectChanges?

entity-framework entity-framework-6

Popular Answer

based on a Msdn reference (https://msdn.microsoft.com/en-us/data/jj556205.aspx)context.Configuration.AutoDetectChangesEnabled = false; will prevent auto change detection from occurring, and as a resultcontext.SaveChanges(); won't save any modifications.

The appropriate techniques are:

context.Configuration.AutoDetectChangesEnabled = false;
//your changes starts
var grand = context.Destinations.Single(d => d.Name == "Grand Canyon");
grand.Description = "Changed here";
//your changes ends
context.Configuration.AutoDetectChangesEnabled = true; //enabling the auto detect
context.SaveChanges();

OR (how you did it)

context.Configuration.AutoDetectChangesEnabled = false;
//your changes starts
var grand = context.Destinations.Single(d => d.Name == "Grand Canyon");
grand.Description = "Changed here";
//your changes ends
context.ChangeTracker.DetectChanges(); // manually ask for changes detection
context.SaveChanges();        

OR

never setcontext.Configuration.AutoDetectChangesEnabled to false , unless it develops into a performance problem.

5
11/27/2015 4:48:16 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow