mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-08-03 10:07:59 +08:00
- 优化 DbContext/Repository Orm 属性进行 CURD 与自身事务相同【新突破】;#270
This commit is contained in:
@ -11,7 +11,7 @@ namespace FreeSql
|
||||
protected IBaseRepository _repo;
|
||||
public RepositoryDbContext(IFreeSql orm, IBaseRepository repo) : base()
|
||||
{
|
||||
_ormPriv = orm;
|
||||
_ormScoped = DbContextScopedFreeSql.Create(orm, () => this, () => repo.UnitOfWork);
|
||||
_isUseUnitOfWork = false;
|
||||
UnitOfWork = repo.UnitOfWork;
|
||||
_repo = repo;
|
||||
@ -23,7 +23,7 @@ namespace FreeSql
|
||||
{
|
||||
if (_dicSet.ContainsKey(entityType)) return _dicSet[entityType];
|
||||
|
||||
var tb = _ormPriv.CodeFirst.GetTableByEntity(entityType);
|
||||
var tb = OrmOriginal.CodeFirst.GetTableByEntity(entityType);
|
||||
if (tb == null) return null;
|
||||
|
||||
object repo = _repo;
|
||||
|
@ -34,7 +34,7 @@ namespace FreeSql
|
||||
if (entitys != null)
|
||||
foreach (var entity in entitys)
|
||||
if (filter.Value.ExpressionDelegate?.Invoke(entity) == false)
|
||||
throw new Exception($"FreeSql.Repository Update 失败,因为设置了过滤器 {filter.Key}: {filter.Value.Expression},更新的数据不符合 {_db.Orm.GetEntityString(_entityType, entity)}");
|
||||
throw new Exception($"FreeSql.Repository Update 失败,因为设置了过滤器 {filter.Key}: {filter.Value.Expression},更新的数据不符合 {_db.OrmOriginal.GetEntityString(_entityType, entity)}");
|
||||
update.Where(filter.Value.Expression);
|
||||
}
|
||||
return update.AsTable(_repo.AsTableValueInternal);
|
||||
@ -58,7 +58,7 @@ namespace FreeSql
|
||||
if (entitys != null)
|
||||
foreach (var entity in entitys)
|
||||
if (filter.Value.ExpressionDelegate?.Invoke(entity) == false)
|
||||
throw new Exception($"FreeSql.Repository Insert 失败,因为设置了过滤器 {filter.Key}: {filter.Value.Expression},插入的数据不符合 {_db.Orm.GetEntityString(_entityType, entity)}");
|
||||
throw new Exception($"FreeSql.Repository Insert 失败,因为设置了过滤器 {filter.Key}: {filter.Value.Expression},插入的数据不符合 {_db.OrmOriginal.GetEntityString(_entityType, entity)}");
|
||||
}
|
||||
return insert.AsTable(_repo.AsTableValueInternal);
|
||||
}
|
||||
|
Reference in New Issue
Block a user