mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 处理 PgArrayToMany AsSelect 子查询 #1145
This commit is contained in:
parent
50a8d979a5
commit
a50c14e77a
@ -862,6 +862,12 @@ namespace FreeSql
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var atms = navs.Where(a => a.Item1.RefType == TableRefType.PgArrayToMany).ToList();
|
||||||
|
if (atms.Any())
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (dbset == rootDbSet)
|
if (dbset == rootDbSet)
|
||||||
{
|
{
|
||||||
if (CanRemove(data, true) == false) return;
|
if (CanRemove(data, true) == false) return;
|
||||||
|
@ -1195,20 +1195,33 @@ namespace FreeSql.Internal
|
|||||||
if (fsql != null)
|
if (fsql != null)
|
||||||
{
|
{
|
||||||
if (asSelectParentExp != null)
|
if (asSelectParentExp != null)
|
||||||
{ //执行 AsSelect() 的关联,OneToMany,ManyToMany
|
{
|
||||||
|
//执行 AsSelect() 的关联,OneToMany,ManyToMany,PgArrayToMany
|
||||||
if (fsqltables[0].Parameter == null)
|
if (fsqltables[0].Parameter == null)
|
||||||
{
|
{
|
||||||
fsqltables[0].Alias = $"tb_{fsqltables.Count}";
|
fsqltables[0].Alias = $"tb_{fsqltables.Count}";
|
||||||
fsqltables[0].Parameter = Expression.Parameter(asSelectEntityType, fsqltables[0].Alias);
|
fsqltables[0].Parameter = Expression.Parameter(asSelectEntityType, fsqltables[0].Alias);
|
||||||
}
|
}
|
||||||
var fsqlWhere = _dicExpressionLambdaToSqlAsSelectWhereMethodInfo.GetOrAdd(asSelectEntityType, asSelectEntityType3 =>
|
|
||||||
typeof(ISelect<>).MakeGenericType(asSelectEntityType3).GetMethod("Where", new[] {
|
|
||||||
typeof(Expression<>).MakeGenericType(typeof(Func<,>).MakeGenericType(asSelectEntityType3, typeof(bool)))
|
|
||||||
}));
|
|
||||||
var parm123Tb = _common.GetTableByEntity(asSelectParentExp.Type);
|
var parm123Tb = _common.GetTableByEntity(asSelectParentExp.Type);
|
||||||
var parm123Ref = parm123Tb.GetTableRef(asSelectParentExp1.Member.Name, true);
|
var parm123Ref = parm123Tb.GetTableRef(asSelectParentExp1.Member.Name, true);
|
||||||
if (parm123Ref != null)
|
if (parm123Ref != null)
|
||||||
{
|
{
|
||||||
|
if (parm123Ref.RefType == TableRefType.PgArrayToMany)
|
||||||
|
{
|
||||||
|
var amtReftbname = ExpressionLambdaToSql(Expression.MakeMemberAccess(asSelectParentExp, parm123Tb.Properties[parm123Tb.ColumnsByPosition[0].CsName]), tsc);
|
||||||
|
amtReftbname = amtReftbname.Substring(0, amtReftbname.Length - _common.QuoteSqlName(parm123Tb.ColumnsByPosition[0].Attribute.Name).Length - 1);
|
||||||
|
if (parm123Ref.RefColumns[0] == fsqltables[0].Table.Primarys[0])
|
||||||
|
(fsql as Select0Provider)._where.Append(" AND (").Append($"{amtReftbname}.{_common.QuoteSqlName(parm123Ref.Columns[0].Attribute.Name)} @> {fsqltables[0].Alias}.{_common.QuoteSqlName(parm123Ref.RefColumns[0].Attribute.Name)}").Append(")");
|
||||||
|
else if (parm123Ref.Columns[0] == fsqltables[0].Table.Primarys[0])
|
||||||
|
(fsql as Select0Provider)._where.Append(" AND (").Append($"{amtReftbname}.{_common.QuoteSqlName(parm123Ref.RefColumns[0].Attribute.Name)} @> {fsqltables[0].Alias}.{_common.QuoteSqlName(parm123Ref.Columns[0].Attribute.Name)}").Append(")");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var fsqlWhere = _dicExpressionLambdaToSqlAsSelectWhereMethodInfo.GetOrAdd(asSelectEntityType, asSelectEntityType3 =>
|
||||||
|
typeof(ISelect<>).MakeGenericType(asSelectEntityType3).GetMethod("Where", new[] {
|
||||||
|
typeof(Expression<>).MakeGenericType(typeof(Func<,>).MakeGenericType(asSelectEntityType3, typeof(bool)))
|
||||||
|
}));
|
||||||
var fsqlWhereParam = fsqltables.First().Parameter; //Expression.Parameter(asSelectEntityType);
|
var fsqlWhereParam = fsqltables.First().Parameter; //Expression.Parameter(asSelectEntityType);
|
||||||
Expression fsqlWhereExp = null;
|
Expression fsqlWhereExp = null;
|
||||||
if (parm123Ref.RefType == TableRefType.ManyToMany)
|
if (parm123Ref.RefType == TableRefType.ManyToMany)
|
||||||
@ -1353,6 +1366,7 @@ namespace FreeSql.Internal
|
|||||||
fsqlWhere.Invoke(fsql, new object[] { Expression.Lambda(fsqlWhereExp, fsqlWhereParam) });
|
fsqlWhere.Invoke(fsql, new object[] { Expression.Lambda(fsqlWhereExp, fsqlWhereParam) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
asSelectBefores.Clear();
|
asSelectBefores.Clear();
|
||||||
|
|
||||||
switch (exp3.Method.Name)
|
switch (exp3.Method.Name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user