private static void Write(this IEntityEntryWriter writer, IEnumerable <EntityEntry> entries, SerializationMode mode) { foreach (var entityEntry in entries.OrderedByMetadata( )) { writer.Write(entityEntry, mode); } }
public static async Task <int> SaveChangesAsync(this DbContext context, IEntityEntryWriter writer, CancellationToken cancellationToken = default) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } var snapshots = context.ChangeTracker.Entries( ).GetSnapshots( ); var rowCount = await context.SaveChangesAsync(cancellationToken) .ConfigureAwait(false); foreach (var snapshot in snapshots) { writer.Write(snapshot.EntityEntry, snapshot.EntityState == EntityState.Added ? SerializationMode.ValuesGeneratedOnAdd : SerializationMode.ValuesGeneratedOnUpdate, snapshot.Properties); } return(rowCount); }
public static void SerializeGraphChanges(this DbContext context, IEntityEntryWriter writer, params object [] items) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } writer.Write(context.Graph(items).Where(IsChanged), SerializationMode.Changes); }
public static void SerializeChanges(this DbContext context, IEntityEntryWriter writer) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } writer.Write(context.ChangeTracker.Entries( ).Where(IsChanged), SerializationMode.Changes); }
public static void SerializeGraph(this DbContext context, IEntityEntryWriter writer, object item) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } writer.Write(context.Graph(item), SerializationMode.Full); }
public static int SaveChanges(this DbContext context, IEntityEntryWriter writer) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } var snapshots = context.ChangeTracker.Entries( ).GetSnapshots( ); var rowCount = context.SaveChanges( ); foreach (var snapshot in snapshots) { writer.Write(snapshot.EntityEntry, snapshot.EntityState == EntityState.Added ? SerializationMode.ValuesGeneratedOnAdd : SerializationMode.ValuesGeneratedOnUpdate, snapshot.Properties); } return(rowCount); }