public override void Update(T entity) { //DbEntityEntry dbEntityEntry = DbContext.Entry(entity); //if (dbEntityEntry.State == EntityState.Detached) //{ // DbSet.Attach(entity); //} //dbEntityEntry.State = EntityState.Modified; ctx.Entry(entity).State = EntityState.Modified; //ctx.Entry(entity).Property(e => e.RowVersion).IsModified = false; }
private static void BeforeSaveChangesWithHistory(IEntityFrameworkDbContext dbContext) { DateTime dateTime = DateTime.UtcNow; IModificationHistory entity; EntityState entityState; foreach (var history in dbContext.ChangeTracker.Entries() .Where(e => e.Entity is IModificationHistory && (e.State == EntityState.Added || e.State == EntityState.Modified)) .Select(e => new { Entity = e.Entity as IModificationHistory, e.State })) { entity = history.Entity; entityState = history.State; if (entityState == EntityState.Modified) { dbContext.Entry(entity).Property(e => e.DateCreated).IsModified = false; } if (entityState == EntityState.Added) { entity.DateCreated = dateTime; } entity.DateModified = dateTime; } }