/// <summary> /// Writes all of the items in the changeset to the database. /// </summary> /// <returns></returns> public virtual void SaveChanges() { EntityIndexWriter.ApplyIndexing(); EntityRelationshipWriter.CommitEntityRelationships(ChangeTracker); ChangeTracker.DetectChanges(); CheckEntityValidation(); EntityWriter.Write(ChangeTracker); ChangeTracker.CommitChanges(); }
/// <summary> /// Writes all of the items in the changeset to the database. /// </summary> /// <returns></returns> public virtual async Task SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken)) { await EntityIndexWriter.ApplyIndexingAsync(cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); await EntityRelationshipWriter.CommitEntityRelationshipsAsync(ChangeTracker, cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); ChangeTracker.DetectChanges(); CheckEntityValidation(); cancellationToken.ThrowIfCancellationRequested(); await EntityWriter.WriteAsync(ChangeTracker, cancellationToken).ConfigureAwait(false); ChangeTracker.CommitChanges(); }
public virtual void SaveChanges() { ChangeTracker.DetectChanges(); AfterDetectChanges(); var commands = GenerateWriteCommands(); var writeModelOptions = GetWriteModelOptions(); var commandsByEntityType = commands.GroupBy(c => c.EntityType); foreach (var entityTypeCommands in commandsByEntityType) { var method = GenericsHelper.GetMethodDelegate <Action <IMongoDbConnection, IEnumerable <IWriteCommand>, WriteModelOptions> >( typeof(MongoDbContext), nameof(InternalSaveChanges), entityTypeCommands.Key ); method(Connection, entityTypeCommands, writeModelOptions); } ChangeTracker.CommitChanges(); CommandStaging.CommitChanges(); }
public virtual async Task SaveChangesAsync(CancellationToken cancellationToken = default) { ChangeTracker.DetectChanges(); AfterDetectChanges(); var commands = GenerateWriteCommands(); var writeModelOptions = GetWriteModelOptions(); var commandsByEntityType = commands.GroupBy(c => c.EntityType); foreach (var entityTypeCommands in commandsByEntityType) { var methodAsync = GenericsHelper.GetMethodDelegate <Func <IMongoDbConnection, IEnumerable <IWriteCommand>, WriteModelOptions, CancellationToken, Task> >( typeof(MongoDbContext), nameof(InternalSaveChangesAsync), entityTypeCommands.Key ); await methodAsync(Connection, entityTypeCommands, writeModelOptions, cancellationToken); } ChangeTracker.CommitChanges(); CommandStaging.CommitChanges(); }