Skip to content

Commit

Permalink
Merge pull request #99 from marcwittke/feature/6.2.0
Browse files Browse the repository at this point in the history
EF Core: Manual change detection
  • Loading branch information
marcwittke authored Jul 28, 2020
2 parents 739e2de + bff27a6 commit 6733a8e
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 EfUnitOfWork(IClock clock, ICurrentTHolder<IIdentity> identityHolder, IDo
: 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 6733a8e

Please sign in to comment.