/// <summary> /// Converts changes for given type from a <see cref="DbContext"/> to a <see cref="DeltaSet{T}"/>. /// </summary> /// <typeparam name="T">The entity type to get changes for.</typeparam> /// <param name="store">The <see cref="DbContext"/> where changes are tracked.</param> /// <returns>An instance of <see cref="DeltaSet{T}"/> containing changes for the given type.</returns> public static DeltaSet <T> GetChanges <T>(this DbContext store) where T : class { return(new DeltaSet <T>(store.ChangeTracker.Entries <T>() .Where(e => e.State != EntityState.Unchanged && e.State != EntityState.Detached) .Select(entry => entry.State switch { EntityState.Modified => DeltaEntity.Updated(entry.Entity), EntityState.Added => DeltaEntity.Added(entry.Entity), EntityState.Deleted => DeltaEntity.Removed(entry.Entity), _ => throw new NotSupportedException(), })));
public bool Remove(DeltaEntity <T> item) => _changes.Remove(item);
public bool Contains(DeltaEntity <T> item) => _changes.Contains(item);
public void Add(DeltaEntity <T> item) => _changes.Add(item);