Merge main branches

This commit is contained in:
igeekfan
2022-05-20 03:16:13 +08:00
121 changed files with 1110 additions and 709 deletions

View File

@ -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;
}
};