Пример #1
0
        //I only have to override these two version of SaveChanges, as the other two versions call these
        public override int SaveChanges(bool acceptAllChangesOnSuccess)
        {
            if (_bookUpdater == null)
            {
                //This handles the case where you don't want the automatic write to Cosmos, e.g. when doing bulk loading
                return(base.SaveChanges(acceptAllChangesOnSuccess));
            }

            try
            {
                var thereAreChanges = _bookUpdater.FindBookChangesToProjectToNoSql(this);
                //This stops ChangeTracker being called twice
                ChangeTracker.AutoDetectChangesEnabled = false;
                if (!thereAreChanges)
                {
                    return(base.SaveChanges(acceptAllChangesOnSuccess));
                }
                return(_bookUpdater.CallBaseSaveChangesAndNoSqlWriteInTransaction(this,
                                                                                  () => base.SaveChanges(acceptAllChangesOnSuccess)));
            }
            finally
            {
                ChangeTracker.AutoDetectChangesEnabled = true;
            }
        }
Пример #2
0
 //I only have to override these two version of SaveChanges, as the other two versions call these
 public override int SaveChanges(bool acceptAllChangesOnSuccess)
 {
     try
     {
         var numBooksChanged = _bookUpdater?.FindNumBooksChanged(this) ?? 0;
         //This stops ChangeTracker being called twice
         ChangeTracker.AutoDetectChangesEnabled = false;
         if (numBooksChanged == 0)
         {
             return(base.SaveChanges(acceptAllChangesOnSuccess));
         }
         return(_bookUpdater.CallBaseSaveChangesAndNoSqlWriteInTransaction(this, numBooksChanged,
                                                                           () => base.SaveChanges(acceptAllChangesOnSuccess)));
     }
     finally
     {
         ChangeTracker.AutoDetectChangesEnabled = true;
     }
 }