From 26da8525f6622db000303fbf9aebeaeca2cc8b7d Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 19 Apr 2022 13:47:33 +0800 Subject: [PATCH] Add constraint --- .../SqlSugar/Abstract/QueryableProvider/NavigatManager.cs | 7 +++++++ Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs index a8d443afe..a5218baa7 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs @@ -347,11 +347,13 @@ namespace SqlSugar else if (method.Method.Name == "Select") { var exp = method.Arguments[1]; + var newExp = (exp as LambdaExpression).Body; var types = exp.Type.GetGenericArguments(); if (types != null && types.Length > 0) { var type = types[0]; var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type); + Check.ExceptionEasy(newExp.Type != entityInfo.Type, $" new {newExp.Type .Name}is error ,use Select(it=>new {entityInfo.Type.Name})",$"new {newExp.Type.Name}是错误的,请使用Select(it=>new {entityInfo.Type.Name})"); if (entityInfo.Columns.Count(x => x.Navigat != null) == 0) { result.SelectString = (" " + queryable.QueryBuilder.GetExpressionValue(exp, ResolveExpressType.SelectSingle).GetString()); @@ -401,6 +403,11 @@ namespace SqlSugar Check.Exception(isList == false, $"{_ListCallFunc.First()} need is ToList()", $"{_ListCallFunc.First()} 需要ToList"); result.OrderByString = String.Join(" , ", oredrBy); } + if (result.SelectString.HasValue()) + { + Check.Exception(isList == false, $"{_ListCallFunc.First()} need is ToList()", $"{_ListCallFunc.First()} 需要ToList"); + result.OrderByString = String.Join(" , ", oredrBy); + } return result; } diff --git a/Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec b/Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec index 90f4b541a..e6c4f3e72 100644 --- a/Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec +++ b/Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec @@ -2,7 +2,7 @@ SqlSugarCore - 5.0.7.4 + 5.0.7.5-preview01 sunkaixuan 果糖大数据科技 http://www.apache.org/licenses/LICENSE-2.0.html