mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 优化 EnableCascadeSave 级联保存执行逻辑,提升性能;
This commit is contained in:
parent
3ce21936e5
commit
471bfb6081
@ -328,7 +328,8 @@ namespace FreeSql
|
||||
}
|
||||
break;
|
||||
case Internal.Model.TableRefType.OneToMany:
|
||||
var addlist = isAdd ? new List<object>() : null;
|
||||
var addList = new List<object>();
|
||||
var addOrUpdateList = new List<object>();
|
||||
foreach (var propValItem in propValEach)
|
||||
{
|
||||
for (var colidx = 0; colidx < tref.Columns.Count; colidx++)
|
||||
@ -336,10 +337,20 @@ namespace FreeSql
|
||||
var val = FreeSql.Internal.Utils.GetDataReaderValue(tref.RefColumns[colidx].CsType, _db.OrmOriginal.GetEntityValueWithPropertyName(_table.Type, item, tref.Columns[colidx].CsName));
|
||||
_db.OrmOriginal.SetEntityValueWithPropertyName(tref.RefEntityType, propValItem, tref.RefColumns[colidx].CsName, val);
|
||||
}
|
||||
if (isAdd) addlist.Add(propValItem);
|
||||
else await refSet.AddOrUpdateAsync(propValItem, cancellationToken);
|
||||
if (isAdd) addList.Add(propValItem);
|
||||
else
|
||||
{
|
||||
var flagExists = refSet.ExistsInStates(propValItem);
|
||||
if (flagExists == null) addList.Add(propValItem); //自增/Guid
|
||||
else addOrUpdateList.Add(propValItem); //统一状态管理
|
||||
}
|
||||
}
|
||||
if (addList.Any()) await refSet.AddRangeAsync(addList, cancellationToken);
|
||||
if (addOrUpdateList.Any())
|
||||
{
|
||||
var existsList = await refSet.Select.WhereDynamic(addOrUpdateList).ToListAsync(false, cancellationToken);
|
||||
foreach (var aouItem in addOrUpdateList) await refSet.AddOrUpdateAsync(aouItem, cancellationToken);
|
||||
}
|
||||
if (isAdd) await refSet.AddRangeAsync(addlist, cancellationToken);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
@ -339,7 +339,8 @@ namespace FreeSql
|
||||
}
|
||||
break;
|
||||
case Internal.Model.TableRefType.OneToMany:
|
||||
var addlist = isAdd ? new List<object>() : null;
|
||||
var addList = new List<object>();
|
||||
var addOrUpdateList = new List<object>();
|
||||
foreach (var propValItem in propValEach)
|
||||
{
|
||||
for (var colidx = 0; colidx < tref.Columns.Count; colidx++)
|
||||
@ -347,10 +348,20 @@ namespace FreeSql
|
||||
var val = FreeSql.Internal.Utils.GetDataReaderValue(tref.RefColumns[colidx].CsType, _db.OrmOriginal.GetEntityValueWithPropertyName(_table.Type, item, tref.Columns[colidx].CsName));
|
||||
_db.OrmOriginal.SetEntityValueWithPropertyName(tref.RefEntityType, propValItem, tref.RefColumns[colidx].CsName, val);
|
||||
}
|
||||
if (isAdd) addlist.Add(propValItem);
|
||||
else refSet.AddOrUpdate(propValItem);
|
||||
if (isAdd) addList.Add(propValItem);
|
||||
else
|
||||
{
|
||||
var flagExists = refSet.ExistsInStates(propValItem);
|
||||
if (flagExists == null) addList.Add(propValItem); //自增/Guid
|
||||
else addOrUpdateList.Add(propValItem); //统一状态管理
|
||||
}
|
||||
}
|
||||
if (addList.Any()) refSet.AddRange(addList);
|
||||
if (addOrUpdateList.Any())
|
||||
{
|
||||
var existsList = refSet.Select.WhereDynamic(addOrUpdateList).ToList();
|
||||
foreach (var aouItem in addOrUpdateList) refSet.AddOrUpdate(aouItem);
|
||||
}
|
||||
if (isAdd) refSet.AddRange(addlist);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user