Пример #1
0
 private static void Write(this IEntityEntryWriter writer, IEnumerable <EntityEntry> entries, SerializationMode mode)
 {
     foreach (var entityEntry in entries.OrderedByMetadata( ))
     {
         writer.Write(entityEntry, mode);
     }
 }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }