I'm confusing about whether or not context.SaveChanges
will call DetectChanges
automatically. Most of books and blogs about Entity Framework said it would. But my simple code snippet. It seems like SaveChanges
does not call DetectChanges
.
using (var context = new BreakAwayContext())
{
context.Configuration.AutoDetectChangesEnabled = false;
var grand = context.Destinations.Single(d => d.Name == "Grand Canyon");
grand.Description = "Changed here";
context.SaveChanges();
}
This will not save changed property into database.
This will:
using (var context = new BreakAwayContext())
{
context.Configuration.AutoDetectChangesEnabled = false;
var grand = context.Destinations.Single(d => d.Name == "Grand Canyon");
grand.Description = "Changed here";
context.ChangeTracker.DetectChanges();
context.SaveChanges();
}
Thank you so much.