diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Where.cs b/Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Where.cs index 0942a94f4..20718c4f1 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Where.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Where.cs @@ -21,6 +21,7 @@ namespace OrmTest.UnitTest base.Begin(); for (int i = 0; i < base.Count; i++) { + whereSingle30(); whereSingle29("22"); whereSingle28(); whereSingle27(); @@ -57,6 +58,19 @@ namespace OrmTest.UnitTest } base.End("Where Test"); } + + private void whereSingle30() + { + Expression> exp = it => it.Name == wc.name2; + ExpressionContext expContext = new ExpressionContext(); + expContext.Resolve(exp, ResolveExpressType.WhereSingle); + var value = expContext.Result.GetString(); + var pars = expContext.Parameters; + base.Check(value, pars, "( [Name] = @Name0 )", new List() { + new SugarParameter("@Name0","a") + }, "whereSingle30"); + } + public string Get28(string a) { return a + "1"; } @@ -462,10 +476,12 @@ namespace OrmTest.UnitTest }, "whereSingle25"); } + public static WhereConst wc = new WhereConst() { name2 = "a" }; } public class WhereConst { public static string name { get; set; } + public string name2 { get; set; } } } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs index 09778df27..ce573c49d 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs @@ -109,6 +109,9 @@ namespace SqlSugar } // fetch the root object reference: var constExpr = expression as ConstantExpression; + if (constExpr == null) { + return DynamicInvoke(rootExpression); + } object objReference = constExpr.Value; // "ascend" back whence we came from and resolve object references along the way: while (memberInfos.Count > 0) // or some other break condition