Skip to content

Commit

Permalink
Merge pull request #1148 from dotnetcore/PgArrayToMany
Browse files Browse the repository at this point in the history
Add PgArrayToMany Navigate Objects #1145
  • Loading branch information
2881099 authored Jun 6, 2022
2 parents fba96d7 + a5d0818 commit 4a18864
Show file tree
Hide file tree
Showing 14 changed files with 1,769 additions and 243 deletions.
16 changes: 9 additions & 7 deletions FreeSql.DbContext/DbSet/DbSetAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ async public Task SaveManyAsync(TEntity item, string propertyName, CancellationT
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.PgArrayToMany:
throw new ArgumentException(DbContextStrings.PropertyOfType_IsNot_OneToManyOrManyToMany(_table.Type.FullName, propertyName));
}

Expand All @@ -166,7 +167,7 @@ async public Task SaveManyAsync(TEntity item, string propertyName, CancellationT
try
{
await AddOrUpdateNavigateAsync(item, false, propertyName, cancellationToken);
if (tref.RefType == Internal.Model.TableRefType.OneToMany)
if (tref.RefType == TableRefType.OneToMany)
{
await DbContextFlushCommandAsync(cancellationToken);
//删除没有保存的数据,求出主体的条件
Expand Down Expand Up @@ -213,7 +214,7 @@ async Task AddOrUpdateNavigateAsync(TEntity item, bool isAdd, string propertyNam
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;
Expand All @@ -225,7 +226,8 @@ async Task AddOrUpdateNavigateAsync(TEntity item, bool isAdd, string propertyNam
if (isAdd) await refSet.AddAsync(propValItem);
else await refSet.AddOrUpdateAsync(propValItem);
return;
case Internal.Model.TableRefType.ManyToOne:
case TableRefType.ManyToOne:
case TableRefType.PgArrayToMany:
return;
}
Expand All @@ -234,7 +236,7 @@ async Task AddOrUpdateNavigateAsync(TEntity item, bool isAdd, string propertyNam
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)
{
Expand Down Expand Up @@ -327,7 +329,7 @@ async Task AddOrUpdateNavigateAsync(TEntity item, bool isAdd, string propertyNam
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)
Expand Down
20 changes: 14 additions & 6 deletions FreeSql.DbContext/DbSet/DbSetSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ public void SaveMany(TEntity item, string propertyName)
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.PgArrayToMany:
throw new ArgumentException(DbContextStrings.PropertyOfType_IsNot_OneToManyOrManyToMany(_table.Type.FullName, propertyName));
}

Expand All @@ -177,7 +178,7 @@ public void SaveMany(TEntity item, string propertyName)
try
{
AddOrUpdateNavigate(item, false, propertyName);
if (tref.RefType == Internal.Model.TableRefType.OneToMany)
if (tref.RefType == TableRefType.OneToMany)
{
DbContextFlushCommand();
//删除没有保存的数据,求出主体的条件
Expand Down Expand Up @@ -224,7 +225,7 @@ void AddOrUpdateNavigate(TEntity item, bool isAdd, string propertyName)
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;
Expand All @@ -236,7 +237,8 @@ void AddOrUpdateNavigate(TEntity item, bool isAdd, string propertyName)
if (isAdd) refSet.Add(propValItem);
else refSet.AddOrUpdate(propValItem);
return;
case Internal.Model.TableRefType.ManyToOne:
case TableRefType.ManyToOne:
case TableRefType.PgArrayToMany:
return;
}
Expand Down Expand Up @@ -714,7 +716,7 @@ List<NativeTuple<TableRef, PropertyInfo>> LocalGetNavigates(TableInfo tb)
{
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)
Expand Down Expand Up @@ -860,6 +862,12 @@ void LocalEach(DbSet<object> dbset, IEnumerable<object> items, bool isOneToOne)
}
}

var atms = navs.Where(a => a.Item1.RefType == TableRefType.PgArrayToMany).ToList();
if (atms.Any())
{

}

if (dbset == rootDbSet)
{
if (CanRemove(data, true) == false) return;
Expand Down
9 changes: 0 additions & 9 deletions FreeSql.DbContext/FreeSql.DbContext.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion FreeSql.Tests/FreeSql.Tests/Issues/623.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void MySqlGroupBy()
FacilityCount = a.Sum(a.Value.FacilityCount),
FacilityOpenCount = a.Sum(a.Value.FacilityOpenCount)
});
Assert.Equal(@"SELECT a.`Dot`, sum(a.`FacilityCount`) as1, sum(a.`FacilityOpenCount`) as2
Assert.Equal(@"SELECT a.`Dot` as1, sum(a.`FacilityCount`) as2, sum(a.`FacilityOpenCount`) as3
FROM `ts_facility` a
WHERE (a.`Date` = cast(date_format('2020-12-30 00:00:00.000','%Y-%m-%d') as datetime)) AND (((a.`EnterpriseId`) in (5))) AND (a.`FacilityType` = 1)
GROUP BY a.`Dot`", sql);
Expand Down
Loading

0 comments on commit 4a18864

Please sign in to comment.