/// <summary> /// Determins the changes that are transfered to the persistence layer. /// </summary> /// <returns>ChangeSet.</returns> private ChangeSet GetChangeSet() { var updatedEntries = this.ChangeTracker.Entries().Where(e => e.State == EntityState.Modified && e.Entity != null); var updateChanges = new List<IChange>(); foreach (var dbEntityEntry in updatedEntries) { IList<PropertyChangeInfo> changes = new List<PropertyChangeInfo>(); foreach (var propertyName in dbEntityEntry.CurrentValues.PropertyNames) { var property = dbEntityEntry.Property(propertyName); if (property.IsModified) { changes.Add(new PropertyChangeInfo(propertyName, property.CurrentValue)); } } updateChanges.Add(Change.CreateUpdateChange(dbEntityEntry.Entity, changes)); } var addChanges = this.ChangeTracker.Entries().Where(e => e.State == EntityState.Added && e.Entity != null).Select(e => Change.CreateAddedChange(e.Entity)); var deleteChanges = this.ChangeTracker.Entries().Where(e => e.State == EntityState.Deleted && e.Entity != null).Select(n => Change.CreateDeleteChange(n.Entity)); var allChanges = new List<IChange>(addChanges); allChanges.AddRange(deleteChanges); allChanges.AddRange(updateChanges); return new ChangeSet(typeof(TContext), allChanges); }
/// <summary> /// Determines the changes that are transferred to the persistence layer. /// </summary> /// <returns>ChangeSet.</returns> private ChangeSet GetChangeSet() { var updatedEntries = this.ChangeTracker.Entries() .Where(e => e.State == EntityState.Modified && e.Entity != null); var updateChanges = new List <IChange>(); foreach (var dbEntityEntry in updatedEntries) { IList <PropertyChangeInfo> changes = new List <PropertyChangeInfo>(); foreach (var propertyName in dbEntityEntry.CurrentValues.Properties.Select(p => p.Name)) { var property = dbEntityEntry.Property(propertyName); if (property.Metadata.IsShadowProperty()) { // BUG: Workaround for resetting IsModified of Discriminator property property.IsModified = false; } if (property.IsModified) { changes.Add(new PropertyChangeInfo(propertyName, property.CurrentValue)); } } updateChanges.Add(Change.CreateUpdateChange(dbEntityEntry.Entity, changes)); } var addChanges = this.ChangeTracker.Entries() .Where(e => e.State == EntityState.Added && e.Entity != null) .Select(e => Change.CreateAddedChange(e.Entity)); var deleteChanges = this.ChangeTracker.Entries() .Where(e => e.State == EntityState.Deleted && e.Entity != null) .Select(n => Change.CreateDeleteChange(n.Entity)); var allChanges = new List <IChange>(addChanges); allChanges.AddRange(deleteChanges); allChanges.AddRange(updateChanges); return(new ChangeSet(typeof(TContext), allChanges)); }