From f80308a6eb48974d7eee023ec21a531b7379b1d0 Mon Sep 17 00:00:00 2001 From: 2881099 <2881099@qq.com> Date: Fri, 16 Aug 2019 20:33:59 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BC=98=E5=8C=96=20=E5=AF=BC=E8=88=AA?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E7=9A=84=E5=85=B3=E7=B3=BB=EF=BC=8C=E5=8F=8B?= =?UTF-8?q?=E5=A5=BD=E6=94=AF=E6=8C=81=20int/int=3F=20=E6=98=A0=E5=B0=84?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sqlite/Curd/SqliteSelectTest.cs | 4 ++-- .../SelectProvider/Select1Provider.cs | 10 +++++----- FreeSql/Internal/UtilsExpressionTree.cs | 20 +++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs b/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs index 61912683..45e0f362 100644 --- a/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs +++ b/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs @@ -858,7 +858,7 @@ namespace FreeSql.Tests.Sqlite public class TestInclude_OneToManyModel2 { [Column(IsPrimary = true)] - public int model2id { get; set; } + public int? model2id { get; set; } public virtual TestInclude_OneToManyModel1 model1 { get; set; } public string m2setting { get; set; } @@ -870,7 +870,7 @@ namespace FreeSql.Tests.Sqlite [Column(IsIdentity = true)] public int id { get; set; } - public int? model2111Idaaa { get; set; } + public int model2111Idaaa { get; set; } public string title { get; set; } public List childs2 { get; set; } diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs b/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs index dc445c2a..e0a1a421 100644 --- a/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs +++ b/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs @@ -680,14 +680,14 @@ namespace FreeSql.Internal.CommonProvider subSelect._where.Clear(); if (tbref.Columns.Count == 1) { - var arrExp = Expression.NewArrayInit(tbref.Columns[0].CsType, + var arrExp = Expression.NewArrayInit(tbref.RefColumns[0].CsType, list.Select(a => getListValue(a, tbref.Columns[0].CsName, 0)).Distinct() - .Select(a => Expression.Constant(Convert.ChangeType(a, tbref.Columns[0].CsType))).ToArray()); + .Select(a => Expression.Constant(Utils.GetDataReaderValue(tbref.RefColumns[0].CsType, a), tbref.RefColumns[0].CsType)).ToArray()); var otmExpParm1 = Expression.Parameter(typeof(TNavigate), "a"); - var containsMethod = _dicTypeMethod.GetOrAdd(tbref.Columns[0].CsType, et => new ConcurrentDictionary()).GetOrAdd("Contains", mn => - typeof(Enumerable).GetMethods().Where(a => a.Name == mn).First()).MakeGenericMethod(tbref.Columns[0].CsType); + var containsMethod = _dicTypeMethod.GetOrAdd(tbref.RefColumns[0].CsType, et => new ConcurrentDictionary()).GetOrAdd("Contains", mn => + typeof(Enumerable).GetMethods().Where(a => a.Name == mn).First()).MakeGenericMethod(tbref.RefColumns[0].CsType); var refCol = Expression.MakeMemberAccess(otmExpParm1, tbref2.Properties[tbref.RefColumns[0].CsName]); - if (refCol.Type.IsNullableType()) refCol = Expression.Property(refCol, CommonExpression._dicNullableValueProperty.GetOrAdd(refCol.Type, ct1 => ct1.GetProperty("Value"))); + //if (refCol.Type.IsNullableType()) refCol = Expression.Property(refCol, CommonExpression._dicNullableValueProperty.GetOrAdd(refCol.Type, ct1 => ct1.GetProperty("Value"))); subSelect.Where(Expression.Lambda>( Expression.Call(null, containsMethod, arrExp, refCol), otmExpParm1)); } diff --git a/FreeSql/Internal/UtilsExpressionTree.cs b/FreeSql/Internal/UtilsExpressionTree.cs index db0f3618..ec2d91f5 100644 --- a/FreeSql/Internal/UtilsExpressionTree.cs +++ b/FreeSql/Internal/UtilsExpressionTree.cs @@ -518,7 +518,7 @@ namespace FreeSql.Internal { } - if (trycol != null && trycol.CsType.NullableTypeOrThis() != trytb.Primarys[a].CsType) + if (trycol != null && trycol.CsType.NullableTypeOrThis() != trytb.Primarys[a].CsType.NullableTypeOrThis()) { nvref.Exception = new Exception($"【ManyToMany】导航属性 {trytbTypeName}.{pnv.Name} 解析错误,{tbmid.CsName}.{trycol.CsName} 和 {trytb.CsName}.{trytb.Primarys[a].CsName} 类型不一致"); trytb.AddOrUpdateTableRef(pnv.Name, nvref); @@ -558,7 +558,7 @@ namespace FreeSql.Internal { } - if (trycol != null && trycol.CsType.NullableTypeOrThis() != tbref.Primarys[a].CsType) + if (trycol != null && trycol.CsType.NullableTypeOrThis() != tbref.Primarys[a].CsType.NullableTypeOrThis()) { nvref.Exception = new Exception($"【ManyToMany】导航属性 {trytbTypeName}.{pnv.Name} 解析错误,{tbmid.CsName}.{trycol.CsName} 和 {tbref.CsName}.{tbref.Primarys[a].CsName} 类型不一致"); trytb.AddOrUpdateTableRef(pnv.Name, nvref); @@ -653,10 +653,10 @@ namespace FreeSql.Internal } if (trytb.Primarys.Length > 1) { - if (trytb.Primarys.Select(a => a.CsType).Distinct().Count() == trytb.Primarys.Length) + if (trytb.Primarys.Select(a => a.CsType.NullableTypeOrThis()).Distinct().Count() == trytb.Primarys.Length) { var pkList = trytb.Primarys.ToList(); - bindColumns.Sort((a, b) => pkList.FindIndex(c => c.CsType == a.CsType.NullableTypeOrThis()).CompareTo(pkList.FindIndex(c => c.CsType == b.CsType.NullableTypeOrThis()))); + bindColumns.Sort((a, b) => pkList.FindIndex(c => c.CsType.NullableTypeOrThis() == a.CsType.NullableTypeOrThis()).CompareTo(pkList.FindIndex(c => c.CsType.NullableTypeOrThis() == b.CsType.NullableTypeOrThis()))); } else if (string.Compare(string.Join(",", trytb.Primarys.Select(a => a.CsName).OrderBy(a => a)), string.Join(",", bindColumns.Select(a => a.CsName).OrderBy(a => a)), true) == 0) { @@ -685,7 +685,7 @@ namespace FreeSql.Internal } } - if (trycol != null && trycol.CsType.NullableTypeOrThis() != trytb.Primarys[a].CsType) + if (trycol != null && trycol.CsType.NullableTypeOrThis() != trytb.Primarys[a].CsType.NullableTypeOrThis()) { nvref.Exception = new Exception($"【OneToMany】导航属性 {trytbTypeName}.{pnv.Name} 解析错误,{trytb.CsName}.{trytb.Primarys[a].CsName} 和 {tbref.CsName}.{trycol.CsName} 类型不一致"); trytb.AddOrUpdateTableRef(pnv.Name, nvref); @@ -776,7 +776,7 @@ namespace FreeSql.Internal var isOnoToOne = pnv.PropertyType != trytb.Type && tbref.Properties.Where(z => z.Value.PropertyType == trytb.Type).Any() && tbref.Primarys.Length == trytb.Primarys.Length && - string.Join(",", tbref.Primarys.Select(a => a.CsType.FullName).OrderBy(a => a)) == string.Join(",", trytb.Primarys.Select(a => a.CsType.FullName).OrderBy(a => a)); + string.Join(",", tbref.Primarys.Select(a => a.CsType.NullableTypeOrThis().FullName).OrderBy(a => a)) == string.Join(",", trytb.Primarys.Select(a => a.CsType.NullableTypeOrThis().FullName).OrderBy(a => a)); List bindColumns = new List(); if (pnvBind != null) @@ -803,10 +803,10 @@ namespace FreeSql.Internal } if (tbref.Primarys.Length > 1) { - if (tbref.Primarys.Select(a => a.CsType).Distinct().Count() == tbref.Primarys.Length) + if (tbref.Primarys.Select(a => a.CsType.NullableTypeOrThis()).Distinct().Count() == tbref.Primarys.Length) { var pkList = tbref.Primarys.ToList(); - bindColumns.Sort((a, b) => pkList.FindIndex(c => c.CsType == a.CsType.NullableTypeOrThis()).CompareTo(pkList.FindIndex(c => c.CsType == b.CsType.NullableTypeOrThis()))); + bindColumns.Sort((a, b) => pkList.FindIndex(c => c.CsType.NullableTypeOrThis() == a.CsType.NullableTypeOrThis()).CompareTo(pkList.FindIndex(c => c.CsType.NullableTypeOrThis() == b.CsType.NullableTypeOrThis()))); } else if (string.Compare(string.Join(",", tbref.Primarys.Select(a => a.CsName).OrderBy(a => a)), string.Join(",", bindColumns.Select(a => a.CsName).OrderBy(a => a)), true) == 0) { @@ -831,7 +831,7 @@ namespace FreeSql.Internal //一对一,主键与主键查找 if (isOnoToOne) { - var trytbpks = trytb.Primarys.Where(z => z.CsType == tbref.Primarys[a].CsType); //一对一,按类型 + var trytbpks = trytb.Primarys.Where(z => z.CsType.NullableTypeOrThis() == tbref.Primarys[a].CsType.NullableTypeOrThis()); //一对一,按类型 if (trytbpks.Count() == 1) trycol = trytbpks.First(); else { @@ -850,7 +850,7 @@ namespace FreeSql.Internal } } } - if (trycol != null && trycol.CsType.NullableTypeOrThis() != tbref.Primarys[a].CsType) + if (trycol != null && trycol.CsType.NullableTypeOrThis() != tbref.Primarys[a].CsType.NullableTypeOrThis()) { nvref.Exception = new Exception($"导航属性 {trytbTypeName}.{pnv.Name} 解析错误,{trytb.CsName}.{trycol.CsName} 和 {tbref.CsName}.{tbref.Primarys[a].CsName} 类型不一致"); trytb.AddOrUpdateTableRef(pnv.Name, nvref);