add PgArrayToMany ObservableCollection test #1145

This commit is contained in:
2881099
2022-06-06 21:09:43 +08:00
parent 1a0f0d0f02
commit 53c2793e5e
8 changed files with 1010 additions and 51 deletions

View File

@ -1212,9 +1212,19 @@ namespace FreeSql.Internal
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(")");
{
var dbinfo = _common._orm.CodeFirst.GetDbInfo(parm123Ref.Columns[0].CsType);
(fsql as Select0Provider)._where.Append(" AND (").Append($"{amtReftbname}.{_common.QuoteSqlName(parm123Ref.Columns[0].Attribute.Name)} @> ARRAY[{fsqltables[0].Alias}.{_common.QuoteSqlName(parm123Ref.RefColumns[0].Attribute.Name)}]::{dbinfo?.dbtype}").Append(")");
}
else if (parm123Ref.Columns[0] == parm123Tb.Primarys[0])
{
var dbinfo = _common._orm.CodeFirst.GetDbInfo(parm123Ref.RefColumns[0].CsType);
(fsql as Select0Provider)._where.Append(" AND (").Append($"{fsqltables[0].Alias}.{_common.QuoteSqlName(parm123Ref.RefColumns[0].Attribute.Name)} @> ARRAY[{amtReftbname}.{_common.QuoteSqlName(parm123Ref.Columns[0].Attribute.Name)}]::{dbinfo?.dbtype}").Append(")");
}
else
{
;
}
}
else
{
@ -2213,9 +2223,19 @@ namespace FreeSql.Internal
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)}");
{
var dbinfo = commonExp._common._orm.CodeFirst.GetDbInfo(memberTbref.Columns[0].CsType);
select.Where($"{amtReftbname}.{commonExp._common.QuoteSqlName(memberTbref.Columns[0].Attribute.Name)} @> ARRAY[{select._tables[0].Alias}.{commonExp._common.QuoteSqlName(memberTbref.RefColumns[0].Attribute.Name)}]::{dbinfo?.dbtype}");
}
else if (memberTbref.Columns[0] == exp3Tb.Primarys[0])
{
var dbinfo = commonExp._common._orm.CodeFirst.GetDbInfo(memberTbref.RefColumns[0].CsType);
select.Where($"{select._tables[0].Alias}.{commonExp._common.QuoteSqlName(memberTbref.RefColumns[0].Attribute.Name)} @> ARRAY[{amtReftbname}.{commonExp._common.QuoteSqlName(memberTbref.Columns[0].Attribute.Name)}]::{dbinfo?.dbtype}");
}
else
{
;
}
break;
}

View File

@ -1044,11 +1044,14 @@ namespace FreeSql.Internal
isArrayToMany = trycol != null;
if (isArrayToMany)
{
cscodeExtLogic1 = $" if (this.{trycol.CsName} == null) return null; \r\nif (this.{trycol.CsName}.Any() == false) return new {(propTypeIsObservableCollection ? "ObservableCollection" : "List")}<{propElementType.DisplayCsharp()}>();\r\n";
cscodeExtLogic2 = $" loc2 = this.{trycol.CsName}.Select(a => loc2.FirstOrDefault(b => b.{tbref.Primarys[0].CsName} == a)).ToList();";
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(")");
if (isLazy)
{
cscodeExtLogic1 = $" if (this.{trycol.CsName} == null) return null; \r\nif (this.{trycol.CsName}.Any() == false) return new {(propTypeIsObservableCollection ? "ObservableCollection" : "List")}<{propElementType.DisplayCsharp()}>();\r\n";
cscodeExtLogic2 = $" loc2 = this.{trycol.CsName}.Select(a => loc2.FirstOrDefault(b => b.{tbref.Primarys[0].CsName} == a)).ToList();";
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;
@ -1091,13 +1094,16 @@ namespace FreeSql.Internal
isArrayToMany = trycol != null;
if (isArrayToMany)
{
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())
if (isLazy)
{
lmbdWhere.Append(".Value");
cscodeExtLogic1 = $" 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");
cscodeExtLogic1 = $" if (this.{trytb.Primarys[0].CsName} == null) return null;\r\n";
}
lmbdWhere.Append(")");
}
lmbdWhere.Append(")");
nvref.Columns.Add(trytb.Primarys[0]);
nvref.RefColumns.Add(trycol);
nvref.RefEntityType = tbref.Type;