Skip to content

Commit

Permalink
EF Core: Manual change detection
Browse files Browse the repository at this point in the history
  • Loading branch information
marcwittke committed Jul 28, 2020
1 parent 739e2de commit bff27a6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public static void UpdateTrackingProperties(this DbContext dbContext, string use
Logger.Trace("tracking that {0}[{1}] was modified by {2} at {3:T} UTC", entity.GetType().Name, entity.Id, userId, utcNow);
}
entity.SetModifiedProperties(userId, utcNow);
// this line causes the recent changes of tracking properties to be detected before flushing
entry.State = EntityState.Modified;
}
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ public class EfUnitOfWork : UnitOfWork
: base(clock, identityHolder, eventAggregator, eventBusScope)
{
DbContext = dbContext;
DbContext.ChangeTracker.AutoDetectChangesEnabled = false;
}

public DbContext DbContext { get; }

public override void Flush()
{
DbContext.ChangeTracker.DetectChanges();
base.Flush();
DbContext.SaveChanges();
}
Expand Down

0 comments on commit bff27a6

Please sign in to comment.