- 调整 BaseEntity,移除 BaseTreeEntity、Tenant 租户,改变事务习惯;

This commit is contained in:
28810
2020-05-08 14:49:24 +08:00
parent fc828d15a6
commit 6d5575def1
12 changed files with 128 additions and 605 deletions

View File

@ -42,7 +42,7 @@ public class UserGroup : BaseEntity<UserGroup, int>
```csharp
public class UserGroup : BaseEntity<UserGroup, int>
{
[Column(IsIdentity = false)]
[Column(IsIdentity = false)]
public override int Id { get; set; }
public string GroupName { get; set; }
}
@ -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();
}
```