diff --git a/Src/Asp.Net/SqlServerTest/Program.cs b/Src/Asp.Net/SqlServerTest/Program.cs index f636767fe..9b47ae5dc 100644 --- a/Src/Asp.Net/SqlServerTest/Program.cs +++ b/Src/Asp.Net/SqlServerTest/Program.cs @@ -18,7 +18,7 @@ namespace OrmTest static void Main(string[] args) { // /***Unit Test***/ - new Select(1).Init(); + //new Select(1).Init(); new Field(1).Init(); new Where(1).Init(); new Method(1).Init(); diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Select.cs b/Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Select.cs index c1d17eb3f..9cae7d85b 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Select.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Select.cs @@ -129,9 +129,9 @@ namespace OrmTest.UnitTest "Select.single4 Error"); } - private void single5(int p = 1) + private void single5(DateTime? p = null) { - Expression> exp = it => it.SchoolId.HasValue; + Expression> exp = it => p.HasValue; SqlServerExpressionContext expContext = new SqlServerExpressionContext(); expContext.IsSingle = false; expContext.Resolve(exp, ResolveExpressType.WhereMultiple); diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/UnaryExpressionResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/UnaryExpressionResolve.cs index 3daaeca11..75deb10b5 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/UnaryExpressionResolve.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/UnaryExpressionResolve.cs @@ -59,11 +59,16 @@ namespace SqlSugar { var member = memberExpression.Expression as MemberExpression; parameter.CommonTempData = CommonTempDataType.Result; - this.Expression = member; + var isConst = member.Expression != null && member.Expression is ConstantExpression; + this.Expression = isConst?member.Expression:member; this.Start(); - var result= this.Context.DbMehtods.HasValue(new MethodCallExpressionModel() { Args=new List() { - new MethodCallExpressionArgs() { IsMember=true, MemberName= parameter.CommonTempData , MemberValue=null } - } }); + var methodParamter = isConst ? new MethodCallExpressionArgs() { IsMember=false } : new MethodCallExpressionArgs() { IsMember = true, MemberName = parameter.CommonTempData, MemberValue = null }; + var result = this.Context.DbMehtods.HasValue(new MethodCallExpressionModel() + { + Args = new List() { + methodParamter + } + }); this.Context.Result.Append(result); parameter.CommonTempData = null; }