mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
rename ArrayToMany to PgArrayToMany
This commit is contained in:
parent
710b88e914
commit
53bea5beb1
@ -157,7 +157,7 @@ namespace FreeSql
|
||||
{
|
||||
case TableRefType.OneToOne:
|
||||
case TableRefType.ManyToOne:
|
||||
case TableRefType.ArrayToMany:
|
||||
case TableRefType.PgArrayToMany:
|
||||
throw new ArgumentException(DbContextStrings.PropertyOfType_IsNot_OneToManyOrManyToMany(_table.Type.FullName, propertyName));
|
||||
}
|
||||
|
||||
@ -227,7 +227,7 @@ namespace FreeSql
|
||||
else await refSet.AddOrUpdateAsync(propValItem);
|
||||
return;
|
||||
case TableRefType.ManyToOne:
|
||||
case TableRefType.ArrayToMany:
|
||||
case TableRefType.PgArrayToMany:
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ namespace FreeSql
|
||||
{
|
||||
case TableRefType.OneToOne:
|
||||
case TableRefType.ManyToOne:
|
||||
case TableRefType.ArrayToMany:
|
||||
case TableRefType.PgArrayToMany:
|
||||
throw new ArgumentException(DbContextStrings.PropertyOfType_IsNot_OneToManyOrManyToMany(_table.Type.FullName, propertyName));
|
||||
}
|
||||
|
||||
@ -238,7 +238,7 @@ namespace FreeSql
|
||||
else refSet.AddOrUpdate(propValItem);
|
||||
return;
|
||||
case TableRefType.ManyToOne:
|
||||
case TableRefType.ArrayToMany:
|
||||
case TableRefType.PgArrayToMany:
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ namespace FreeSql.Internal
|
||||
{
|
||||
case TableRefType.ManyToMany:
|
||||
case TableRefType.OneToMany:
|
||||
case TableRefType.ArrayToMany:
|
||||
case TableRefType.PgArrayToMany:
|
||||
continue;
|
||||
}
|
||||
if (_tables.Any(a => a.Alias == $"{map.First().Table.Alias}__{memProp.Name}") == false) continue;
|
||||
@ -2195,7 +2195,13 @@ namespace FreeSql.Internal
|
||||
for (var tidx = 0; tidx < memberTbref.Columns.Count; tidx++)
|
||||
select.Where($"{select._tables[0].Alias}.{commonExp._common.QuoteSqlName(memberTbref.RefColumns[tidx].Attribute.Name)} = {omtReftbname}.{commonExp._common.QuoteSqlName(memberTbref.Columns[tidx].Attribute.Name)}");
|
||||
break;
|
||||
case TableRefType.ArrayToMany:
|
||||
case TableRefType.PgArrayToMany:
|
||||
var amtReftbname = e.FreeParse(Expression.MakeMemberAccess(memberExp.Expression, exp3Tb.Properties[exp3Tb.ColumnsByPosition[0].CsName]));
|
||||
amtReftbname = amtReftbname.Substring(0, amtReftbname.Length - commonExp._common.QuoteSqlName(exp3Tb.ColumnsByPosition[0].Attribute.Name).Length - 1);
|
||||
if (memberTbref.RefColumns[0] == select._tables[0].Table.Primarys[0])
|
||||
select.Where($"{amtReftbname}.{commonExp._common.QuoteSqlName(memberTbref.Columns[0].Attribute.Name)} @> {select._tables[0].Alias}.{commonExp._common.QuoteSqlName(memberTbref.RefColumns[0].Attribute.Name)}");
|
||||
else if (memberTbref.Columns[0] == select._tables[0].Table.Primarys[0])
|
||||
select.Where($"{amtReftbname}.{commonExp._common.QuoteSqlName(memberTbref.RefColumns[0].Attribute.Name)} @> {select._tables[0].Alias}.{commonExp._common.QuoteSqlName(memberTbref.Columns[0].Attribute.Name)}");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -2244,7 +2250,9 @@ namespace FreeSql.Internal
|
||||
if (select != null) return;
|
||||
LocalInitSelectProvider();
|
||||
continue;
|
||||
case TableRefType.ArrayToMany:
|
||||
case TableRefType.PgArrayToMany:
|
||||
if (select != null) return;
|
||||
LocalInitSelectProvider();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -418,6 +418,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
case TableRefType.ManyToMany:
|
||||
case TableRefType.OneToMany:
|
||||
case TableRefType.PgArrayToMany:
|
||||
var funcType = typeof(Func<,>).MakeGenericType(_tables[0].Table.Type, typeof(IEnumerable<>).MakeGenericType(parTbref.RefEntityType));
|
||||
var navigateSelector = Expression.Lambda(funcType, exp, _tables[0].Parameter);
|
||||
var incMethod = this.GetType().GetMethod("IncludeMany");
|
||||
@ -430,8 +431,6 @@ namespace FreeSql.Internal.CommonProvider
|
||||
var curTb = _commonUtils.GetTableByEntity(exp.Type);
|
||||
_commonExpression.ExpressionWhereLambda(_tables, Expression.MakeMemberAccess(exp, curTb.Properties[curTb.ColumnsByCs.First().Value.CsName]), null, null, null);
|
||||
break;
|
||||
case TableRefType.ArrayToMany:
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -1175,7 +1174,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
dicList.Clear();
|
||||
}
|
||||
break;
|
||||
case TableRefType.ArrayToMany:
|
||||
case TableRefType.PgArrayToMany:
|
||||
if (true)
|
||||
{
|
||||
var subList = new List<TNavigate>();
|
||||
|
@ -150,6 +150,6 @@ namespace FreeSql.Internal.Model
|
||||
}
|
||||
public enum TableRefType
|
||||
{
|
||||
OneToOne, ManyToOne, OneToMany, ManyToMany, ArrayToMany
|
||||
OneToOne, ManyToOne, OneToMany, ManyToMany, PgArrayToMany
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
@ -623,6 +624,7 @@ namespace FreeSql.Internal
|
||||
|
||||
//List 或 ICollection,一对多、多对多
|
||||
var propElementType = pnv.PropertyType.GetGenericArguments().FirstOrDefault() ?? pnv.PropertyType.GetElementType();
|
||||
var propTypeIsObservableCollection = propElementType != null && pnv.PropertyType == typeof(ObservableCollection<>).MakeGenericType(propElementType);
|
||||
if (propElementType != null)
|
||||
{
|
||||
if (typeof(IEnumerable).IsAssignableFrom(pnv.PropertyType) == false) return;
|
||||
@ -992,17 +994,18 @@ namespace FreeSql.Internal
|
||||
{
|
||||
var isArrayToMany = false;
|
||||
var lmbdWhere = isLazy ? new StringBuilder() : null;
|
||||
var cscodeExtLogic = "";
|
||||
//Pgsql Array[] To Many
|
||||
if (common._orm.Ado.DataType == DataType.PostgreSQL)
|
||||
{
|
||||
//class User {
|
||||
// public int[] RoleIds { get; set; }
|
||||
// [Navigate(nameof(RoleIds))]
|
||||
// public Role[] Roles { get; set; }
|
||||
// public List<Role> Roles { get; set; }
|
||||
//}
|
||||
//class Role {
|
||||
// [Navigate(nameof(User.RoleIds))]
|
||||
// public User[] Users { get; set; }
|
||||
// public List<User> Users { get; set; }
|
||||
//}
|
||||
ColumnInfo trycol = null;
|
||||
if (tbref.Primarys.Length == 1)
|
||||
@ -1038,11 +1041,14 @@ namespace FreeSql.Internal
|
||||
isArrayToMany = trycol != null;
|
||||
if (isArrayToMany)
|
||||
{
|
||||
lmbdWhere.Append("this.").Append(trycol.CsName).Append(".Contains(a.").Append(tbref.Primarys[0].CsName).Append(")");
|
||||
cscodeExtLogic = $" if (this.{trycol.CsName} == null) return null; \r\nif (this.{trycol.CsName}.Any() == false) return new {(propTypeIsObservableCollection ? "ObservableCollection" : "List")}<{propElementType.DisplayCsharp()}>();\r\n";
|
||||
lmbdWhere.Append("this.").Append(trycol.CsName).Append(".Contains(a.").Append(tbref.Primarys[0].CsName);
|
||||
if (trycol.CsType.GetElementType().IsNullableType() == false && tbref.Primarys[0].CsType.IsNullableType()) lmbdWhere.Append(".Value");
|
||||
lmbdWhere.Append(")");
|
||||
nvref.Columns.Add(trycol);
|
||||
nvref.RefColumns.Add(tbref.Primarys[0]);
|
||||
nvref.RefEntityType = tbref.Type;
|
||||
nvref.RefType = TableRefType.ArrayToMany;
|
||||
nvref.RefType = TableRefType.PgArrayToMany;
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
}
|
||||
}
|
||||
@ -1080,11 +1086,14 @@ namespace FreeSql.Internal
|
||||
isArrayToMany = trycol != null;
|
||||
if (isArrayToMany)
|
||||
{
|
||||
lmbdWhere.Append("a.").Append(trycol.CsName).Append(".Contains(this.").Append(trytb.Primarys[0].CsName).Append(")");
|
||||
cscodeExtLogic = $" if (this.{trytb.Primarys[0].CsName} == null) return null;\r\n";
|
||||
lmbdWhere.Append("a.").Append(trycol.CsName).Append(".Contains(this.").Append(trytb.Primarys[0].CsName);
|
||||
if (trycol.CsType.GetElementType().IsNullableType() == false && trytb.Primarys[0].CsType.IsNullableType()) lmbdWhere.Append(".Value");
|
||||
lmbdWhere.Append(")");
|
||||
nvref.Columns.Add(tbref.Primarys[0]);
|
||||
nvref.RefColumns.Add(trycol);
|
||||
nvref.RefEntityType = tbref.Type;
|
||||
nvref.RefType = TableRefType.ArrayToMany;
|
||||
nvref.RefType = TableRefType.PgArrayToMany;
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
}
|
||||
}
|
||||
@ -1205,6 +1214,7 @@ namespace FreeSql.Internal
|
||||
if (vp?.Item2 == true)
|
||||
{ //get 重写
|
||||
cscode.Append(" ").Append(propGetModification).Append(" get {\r\n")
|
||||
.Append(cscodeExtLogic)
|
||||
.Append(" if (base.").Append(pnv.Name).Append(" == null && __lazy__").Append(pnv.Name).AppendLine(" == false) {");
|
||||
|
||||
if (nvref.Exception == null)
|
||||
|
Loading…
x
Reference in New Issue
Block a user