mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 01:05:27 +08:00 
			
		
		
		
	- 优化 Repository EndEdit 以事务方式执行,若外部未设置事务则自己开启事务;
This commit is contained in:
		@@ -142,7 +142,33 @@ namespace FreeSql
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void BeginEdit(List<TEntity> data) => _dbset.BeginEdit(data);
 | 
					        public void BeginEdit(List<TEntity> data) => _dbset.BeginEdit(data);
 | 
				
			||||||
        public int EndEdit() => _dbset.EndEdit();
 | 
					        public int EndEdit()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            _db.FlushCommand();
 | 
				
			||||||
 | 
					            if (UnitOfWork?.GetOrBeginTransaction(true) == null && _db.OrmOriginal.Ado.TransactionCurrentThread == null)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                int affrows = 0;
 | 
				
			||||||
 | 
					                IUnitOfWork olduow = UnitOfWork;
 | 
				
			||||||
 | 
					                UnitOfWork = new UnitOfWork(_db.OrmOriginal);
 | 
				
			||||||
 | 
					                try
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    affrows = _dbset.EndEdit();
 | 
				
			||||||
 | 
					                    UnitOfWork.Commit();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                catch
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    UnitOfWork.Rollback();
 | 
				
			||||||
 | 
					                    throw;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                finally
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    UnitOfWork.Dispose();
 | 
				
			||||||
 | 
					                    UnitOfWork = olduow;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                return affrows;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return _dbset.EndEdit();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public abstract partial class BaseRepository<TEntity, TKey> : BaseRepository<TEntity>, IBaseRepository<TEntity, TKey>
 | 
					    public abstract partial class BaseRepository<TEntity, TKey> : BaseRepository<TEntity>, IBaseRepository<TEntity, TKey>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user