mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 17:20:49 +08:00 
			
		
		
		
	update BaseEntity readme
This commit is contained in:
		@@ -90,3 +90,37 @@ var items = UserGroup.Where(a => a.Id > 10).ToList();
 | 
			
		||||
支持多表查询时,软删除条件会附加在每个表中;
 | 
			
		||||
 | 
			
		||||
> 有关更多查询方法,请参考资料:https://github.com/2881099/FreeSql/wiki/%e6%9f%a5%e8%af%a2
 | 
			
		||||
 | 
			
		||||
# 事务建议
 | 
			
		||||
 | 
			
		||||
由于 AsyncLocal 平台兼容不好,所以交给外部管理。
 | 
			
		||||
 | 
			
		||||
```csharp
 | 
			
		||||
static AsyncLocal<IUnitOfWork> _asyncUow = new AsyncLocal<IUnitOfWork>();
 | 
			
		||||
 | 
			
		||||
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
在 Scoped 开始时: _asyncUow.Value = fsql.CreateUnitOfWork(); (也可以使用 UnitOfWorkManager 对象获取 uow)
 | 
			
		||||
 | 
			
		||||
在 Scoped 结束时:_asyncUow.Value = null;
 | 
			
		||||
 | 
			
		||||
如下:
 | 
			
		||||
 | 
			
		||||
```csharp
 | 
			
		||||
using (var uow = fsql.CreateUnitOfWork())
 | 
			
		||||
{
 | 
			
		||||
    _asyncUow.Value = uow;
 | 
			
		||||
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        //todo ...
 | 
			
		||||
    }
 | 
			
		||||
    finally
 | 
			
		||||
    {
 | 
			
		||||
        _asyncUow.Value = null;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    uow.Commit();
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user