mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 修复 DbContext/Repository SaveMany 一对多保存时删除条件 bug;
This commit is contained in:
@ -170,10 +170,25 @@ namespace FreeSql
|
||||
if (tref.RefType == Internal.Model.TableRefType.OneToMany)
|
||||
{
|
||||
DbContextExecCommand();
|
||||
//删除没有保存的数据
|
||||
//删除没有保存的数据,求出主体的条件
|
||||
var deleteWhereParentParam = Expression.Parameter(typeof(object), "a");
|
||||
Expression whereParentExp = null;
|
||||
for (var colidx = 0; colidx < tref.Columns.Count; colidx++)
|
||||
{
|
||||
var whereExp = Expression.Equal(
|
||||
Expression.MakeMemberAccess(Expression.Convert(deleteWhereParentParam, tref.RefEntityType), tref.RefColumns[colidx].Table.Properties[tref.RefColumns[colidx].CsName]),
|
||||
Expression.Constant(
|
||||
FreeSql.Internal.Utils.GetDataReaderValue(
|
||||
tref.Columns[colidx].CsType,
|
||||
_db.Orm.GetEntityValueWithPropertyName(_table.Type, item, tref.Columns[colidx].CsName)), tref.RefColumns[colidx].CsType)
|
||||
);
|
||||
if (whereParentExp == null) whereParentExp = whereExp;
|
||||
else whereParentExp = Expression.AndAlso(whereParentExp, whereExp);
|
||||
}
|
||||
var propValEach = GetItemValue(item, prop) as IEnumerable;
|
||||
_db.Orm.Delete<object>().AsType(tref.RefEntityType)
|
||||
.WithTransaction(_uow?.GetOrBeginTransaction())
|
||||
.Where(Expression.Lambda<Func<object, bool>>(whereParentExp, deleteWhereParentParam))
|
||||
.WhereDynamic(propValEach, true).ExecuteAffrows();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user