From b9a9106f86c57e48cce4434cae3db66f127e0d4a Mon Sep 17 00:00:00 2001 From: 28810 <28810@YEXIANGQIN> Date: Sat, 26 Jan 2019 10:32:53 +0800 Subject: [PATCH] =?UTF-8?q?lazy=E5=BB=B6=E6=97=B6=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E7=88=B6=E5=AD=90=E5=85=B3=E7=B3=BB=E7=9A=841v=E5=A4=9A?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=88=A4=E6=96=AD=E4=BF=AE=E6=AD=A3=EF=BC=8C?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=20int=3F=20!=3D=20int=20=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs | 1 + FreeSql/Extensions/FreeSqlGlobalExtensions.cs | 1 + FreeSql/Internal/UtilsExpressionTree.cs | 8 ++++---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs b/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs index 4dcc2451..8e084823 100644 --- a/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs +++ b/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs @@ -74,6 +74,7 @@ namespace FreeSql.Tests.MySql { public string Name { get; set; } public virtual ICollection Songs { get; set; } + public virtual ICollection Tags { get; set; } } diff --git a/FreeSql/Extensions/FreeSqlGlobalExtensions.cs b/FreeSql/Extensions/FreeSqlGlobalExtensions.cs index 350b2109..64468f2f 100644 --- a/FreeSql/Extensions/FreeSqlGlobalExtensions.cs +++ b/FreeSql/Extensions/FreeSqlGlobalExtensions.cs @@ -27,6 +27,7 @@ public static class FreeSqlGlobalExtensions { }); public static bool IsNumberType(this Type that) => that == null ? false : dicIsNumberType.Value.ContainsKey(that); public static bool IsNullableType(this Type that) => that?.FullName.StartsWith("System.Nullable`1[") == true; + internal static Type NullableTypeOrThis(this Type that) => that?.IsNullableType() == true ? that.GenericTypeArguments.First() : that; /// /// 测量两个经纬度的距离,返回单位:米 diff --git a/FreeSql/Internal/UtilsExpressionTree.cs b/FreeSql/Internal/UtilsExpressionTree.cs index 95318dd7..f8ce0e81 100644 --- a/FreeSql/Internal/UtilsExpressionTree.cs +++ b/FreeSql/Internal/UtilsExpressionTree.cs @@ -260,7 +260,7 @@ namespace FreeSql.Internal { ) { } - if (trycol != null && trycol.CsType != trytb.Primarys[a].CsType) + if (trycol != null && trycol.CsType.NullableTypeOrThis() != trytb.Primarys[a].CsType) throw new Exception($"【延时加载ManyToMany】导航属性 {trytbTypeName}.{vp.Item1.Name} 解析错误,{tbmid.CsName}.{trycol.CsName} 和 {trytb.CsName}.{trytb.Primarys[a].CsName} 类型不一致"); if (trycol == null) throw new Exception($"【延时加载ManyToMany】导航属性 {trytbTypeName}.{vp.Item1.Name} 在 {tbmid.CsName} 中没有找到对应的字段,如:{midTypePropsTrytb.Name}{findtrytbPkCsName}、{midTypePropsTrytb.Name}_{findtrytbPkCsName}"); @@ -278,7 +278,7 @@ namespace FreeSql.Internal { ) { } - if (trycol != null && trycol.CsType != tbref.Primarys[a].CsType) + if (trycol != null && trycol.CsType.NullableTypeOrThis() != tbref.Primarys[a].CsType) throw new Exception($"【延时加载ManyToMany】导航属性 {tbrefTypeName}.{vp.Item1.Name} 解析错误,{tbmid.CsName}.{trycol.CsName} 和 {tbref.CsName}.{tbref.Primarys[a].CsName} 类型不一致"); if (trycol == null) throw new Exception($"【延时加载ManyToMany】导航属性 {tbrefTypeName}.{vp.Item1.Name} 在 {tbmid.CsName} 中没有找到对应的字段,如:{midTypePropsTbref.Name}{findtbrefPkCsName}、{midTypePropsTbref.Name}_{findtbrefPkCsName}"); @@ -323,7 +323,7 @@ namespace FreeSql.Internal { { } - if (trycol != null && trycol.CsType != trytb.Primarys[a].CsType) + if (trycol != null && trycol.CsType.NullableTypeOrThis() != trytb.Primarys[a].CsType) throw new Exception($"【延时加载OneToMany】导航属性 {trytbTypeName}.{vp.Item1.Name} 解析错误,{trytb.CsName}.{trytb.Primarys[a].CsName} 和 {tbref.CsName}.{trycol.CsName} 类型不一致"); if (trycol == null) throw new Exception($"【延时加载OneToMany】导航属性 {trytbTypeName}.{vp.Item1.Name} 在 {tbref.CsName} 中没有找到对应的字段,如:{findtrytb}{findtrytbPkCsName}、{findtrytb}_{findtrytbPkCsName}" + (refprop == null ? "" : $"、{refprop.Name}{findtrytbPkCsName}、{refprop.Name}_{findtrytbPkCsName}")); @@ -397,7 +397,7 @@ namespace FreeSql.Internal { } } } - if (trycol != null && trycol.CsType != tbref.Primarys[a].CsType) + if (trycol != null && trycol.CsType.NullableTypeOrThis() != tbref.Primarys[a].CsType) throw new Exception($"【延时加载】导航属性 {trytbTypeName}.{vp.Item1.Name} 解析错误,{trytb.CsName}.{trycol.CsName} 和 {tbref.CsName}.{tbref.Primarys[a].CsName} 类型不一致"); if (trycol == null) throw new Exception($"【延时加载】导航属性 {trytbTypeName}.{vp.Item1.Name} 没有找到对应的字段,如:{vp.Item1.Name}{findtbrefPkCsName}、{vp.Item1.Name}_{findtbrefPkCsName}");