mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
fix PgArrayToMany
This commit is contained in:
@ -150,6 +150,22 @@ namespace FreeSql.Internal.Model
|
||||
}
|
||||
public enum TableRefType
|
||||
{
|
||||
OneToOne, ManyToOne, OneToMany, ManyToMany, PgArrayToMany
|
||||
OneToOne, ManyToOne, OneToMany, ManyToMany,
|
||||
/// <summary>
|
||||
/// PostgreSQL 数组类型专属功能<para></para>
|
||||
/// 方式一:select * from Role where Id in (RoleIds)<para></para>
|
||||
/// class User {<para></para>
|
||||
/// ____public int[] RoleIds { get; set; }<para></para>
|
||||
/// ____[Navigate(nameof(RoleIds))]<para></para>
|
||||
/// ____public List<Role> Roles { get; set; }<para></para>
|
||||
/// }<para></para>
|
||||
/// 方式二:select * from User where RoleIds @> Id<para></para>
|
||||
/// class Role {<para></para>
|
||||
/// ____public int Id { get; set; }<para></para>
|
||||
/// ____[Navigate(nameof(User.RoleIds))]<para></para>
|
||||
/// ____public List<User> Users { get; set; }<para></para>
|
||||
/// }<para></para>
|
||||
/// </summary>
|
||||
PgArrayToMany
|
||||
}
|
||||
}
|
@ -1014,7 +1014,8 @@ namespace FreeSql.Internal
|
||||
{
|
||||
if (trytb.ColumnsByCs.TryGetValue(pnvBind[0], out trycol))
|
||||
{
|
||||
if (trycol.CsType.IsArray == true && tbref.Primarys[0].CsType.NullableTypeOrThis() != trycol.CsType.GetElementType().NullableTypeOrThis())
|
||||
if (trycol.CsType.IsArray == false) trycol = null;
|
||||
else if (trycol != null && tbref.Primarys[0].CsType.NullableTypeOrThis() != trycol.CsType.GetElementType().NullableTypeOrThis())
|
||||
{
|
||||
nvref.Exception = new Exception($"导航属性 {trytbTypeName}.{pnv.Name} 特性 [Navigate] 解析错误,{trytbTypeName}.{trycol.CsName} 数组元素 与 {tbrefTypeName}.{tbref.Primarys[0].CsName} 类型不符");
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
@ -1022,7 +1023,7 @@ namespace FreeSql.Internal
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nvref.Exception == null && trycol == null)
|
||||
if (pnvBind == null && trycol == null)
|
||||
{
|
||||
var findtbrefPkCsName = tbref.Primarys[0].CsName.TrimStart('_');
|
||||
if (findtbrefPkCsName.StartsWith(trytb.Type.Name, StringComparison.CurrentCultureIgnoreCase)) findtbrefPkCsName = findtbrefPkCsName.Substring(trytb.Type.Name.Length).TrimStart('_');
|
||||
@ -1059,7 +1060,8 @@ namespace FreeSql.Internal
|
||||
{
|
||||
if (tbref.ColumnsByCs.TryGetValue(pnvBind[0], out trycol))
|
||||
{
|
||||
if (trycol.CsType.IsArray == true && trytb.Primarys[0].CsType.NullableTypeOrThis() != trycol.CsType.GetElementType().NullableTypeOrThis())
|
||||
if (trycol.CsType.IsArray == false) trycol = null;
|
||||
else if (trytb.Primarys[0].CsType.NullableTypeOrThis() != trycol.CsType.GetElementType().NullableTypeOrThis())
|
||||
{
|
||||
nvref.Exception = new Exception($"导航属性 {trytbTypeName}.{pnv.Name} 特性 [Navigate] 解析错误,{trytbTypeName}.{trytb.Primarys[0].CsName} 与 {tbrefTypeName}.{trycol.CsName} 数组元素类型不符");
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
@ -1067,7 +1069,7 @@ namespace FreeSql.Internal
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nvref.Exception == null && trycol == null)
|
||||
if (pnvBind != null && trycol == null)
|
||||
{
|
||||
var findtrytbPkCsName = trytb.Primarys[0].CsName.TrimStart('_');
|
||||
if (findtrytbPkCsName.StartsWith(trytb.Type.Name, StringComparison.CurrentCultureIgnoreCase)) findtrytbPkCsName = findtrytbPkCsName.Substring(trytb.Type.Name.Length).TrimStart('_');
|
||||
@ -1086,9 +1088,12 @@ namespace FreeSql.Internal
|
||||
isArrayToMany = trycol != null;
|
||||
if (isArrayToMany)
|
||||
{
|
||||
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");
|
||||
if (trycol.CsType.GetElementType().IsNullableType() == false && trytb.Primarys[0].CsType.IsNullableType())
|
||||
{
|
||||
lmbdWhere.Append(".Value");
|
||||
cscodeExtLogic = $" if (this.{trytb.Primarys[0].CsName} == null) return null;\r\n";
|
||||
}
|
||||
lmbdWhere.Append(")");
|
||||
nvref.Columns.Add(tbref.Primarys[0]);
|
||||
nvref.RefColumns.Add(trycol);
|
||||
|
Reference in New Issue
Block a user