Пример #1
0
        public override async Task <int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = new CancellationToken())
        {
            if (_bookUpdater == null)
            {
                //This handles the case where you don't want the automatic write to Cosmos, e.g. when doing bulk loading
                return(await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken));
            }

            try
            {
                var thereAreChanges = _bookUpdater.FindBookChangesToProjectToNoSql(this);
                //This stops ChangeTracker being called twice
                ChangeTracker.AutoDetectChangesEnabled = false;
                if (!thereAreChanges)
                {
                    return(await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken));
                }
                return(await _bookUpdater.CallBaseSaveChangesWithNoSqlWriteInTransactionAsync(this,
                                                                                              () => base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken)));
            }
            finally
            {
                ChangeTracker.AutoDetectChangesEnabled = true;
            }
        }
Пример #2
0
 public override async Task <int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default(CancellationToken))
 {
     try
     {
         var numBooksChanged = _bookUpdater?.FindNumBooksChanged(this) ?? 0;
         //This stops ChangeTracker being called twice
         ChangeTracker.AutoDetectChangesEnabled = false;
         if (numBooksChanged == 0)
         {
             return(await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken));
         }
         return(await _bookUpdater.CallBaseSaveChangesWithNoSqlWriteInTransactionAsync(this, numBooksChanged,
                                                                                       () => base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken)));
     }
     finally
     {
         ChangeTracker.AutoDetectChangesEnabled = true;
     }
 }