init ArrayToMany

This commit is contained in:
2881099
2022-06-04 00:35:33 +08:00
parent 24f55fa0f4
commit 8248057d5c
6 changed files with 223 additions and 105 deletions

View File

@ -155,8 +155,9 @@ namespace FreeSql
if (tref == null) return;
switch (tref.RefType)
{
case Internal.Model.TableRefType.OneToOne:
case Internal.Model.TableRefType.ManyToOne:
case TableRefType.OneToOne:
case TableRefType.ManyToOne:
case TableRefType.ArrayToMany:
throw new ArgumentException(DbContextStrings.PropertyOfType_IsNot_OneToManyOrManyToMany(_table.Type.FullName, propertyName));
}
@ -166,7 +167,7 @@ namespace FreeSql
try
{
await AddOrUpdateNavigateAsync(item, false, propertyName, cancellationToken);
if (tref.RefType == Internal.Model.TableRefType.OneToMany)
if (tref.RefType == TableRefType.OneToMany)
{
await DbContextFlushCommandAsync(cancellationToken);
//删除没有保存的数据,求出主体的条件
@ -213,7 +214,7 @@ namespace FreeSql
DbSet<object> refSet = null;
switch (tref.RefType)
{
case Internal.Model.TableRefType.OneToOne:
case TableRefType.OneToOne:
refSet = GetDbSetObject(tref.RefEntityType);
var propValItem = GetItemValue(item, prop);
if (propValItem == null) return;
@ -225,7 +226,8 @@ namespace FreeSql
if (isAdd) await refSet.AddAsync(propValItem);
else await refSet.AddOrUpdateAsync(propValItem);
return;
case Internal.Model.TableRefType.ManyToOne:
case TableRefType.ManyToOne:
case TableRefType.ArrayToMany:
return;
}
@ -234,7 +236,7 @@ namespace FreeSql
refSet = GetDbSetObject(tref.RefEntityType);
switch (tref.RefType)
{
case Internal.Model.TableRefType.ManyToMany:
case TableRefType.ManyToMany:
var curList = new List<object>();
foreach (var propValItem in propValEach)
{
@ -327,7 +329,7 @@ namespace FreeSql
await midSet.AddRangeAsync(midListAdd, cancellationToken);
}
break;
case Internal.Model.TableRefType.OneToMany:
case TableRefType.OneToMany:
var addList = new List<object>();
var addOrUpdateList = new List<object>();
foreach (var propValItem in propValEach)

View File

@ -166,8 +166,9 @@ namespace FreeSql
if (tref == null) return;
switch (tref.RefType)
{
case Internal.Model.TableRefType.OneToOne:
case Internal.Model.TableRefType.ManyToOne:
case TableRefType.OneToOne:
case TableRefType.ManyToOne:
case TableRefType.ArrayToMany:
throw new ArgumentException(DbContextStrings.PropertyOfType_IsNot_OneToManyOrManyToMany(_table.Type.FullName, propertyName));
}
@ -177,7 +178,7 @@ namespace FreeSql
try
{
AddOrUpdateNavigate(item, false, propertyName);
if (tref.RefType == Internal.Model.TableRefType.OneToMany)
if (tref.RefType == TableRefType.OneToMany)
{
DbContextFlushCommand();
//删除没有保存的数据,求出主体的条件
@ -224,7 +225,7 @@ namespace FreeSql
DbSet<object> refSet = null;
switch (tref.RefType)
{
case Internal.Model.TableRefType.OneToOne:
case TableRefType.OneToOne:
refSet = GetDbSetObject(tref.RefEntityType);
var propValItem = GetItemValue(item, prop);
if (propValItem == null) return;
@ -236,7 +237,8 @@ namespace FreeSql
if (isAdd) refSet.Add(propValItem);
else refSet.AddOrUpdate(propValItem);
return;
case Internal.Model.TableRefType.ManyToOne:
case TableRefType.ManyToOne:
case TableRefType.ArrayToMany:
return;
}
@ -714,7 +716,7 @@ namespace FreeSql
{
return tb.Properties.Where(a => tb.ColumnsByCs.ContainsKey(a.Key) == false)
.Select(a => new NativeTuple<TableRef, PropertyInfo>(tb.GetTableRef(a.Key, false), a.Value))
.Where(a => a.Item1 != null && a.Item1.RefType != TableRefType.ManyToOne)
.Where(a => a.Item1 != null && new[] { TableRefType.OneToOne, TableRefType.OneToMany, TableRefType.ManyToMany }.Contains(a.Item1.RefType))
.ToList();
}
void LocalEach(DbSet<object> dbset, IEnumerable<object> items, bool isOneToOne)