Browse Source

Expression Bug

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
68c0435619
  1. 16
      Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Where.cs
  2. 3
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs

16
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<Func<Student, bool>> 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<SugarParameter>() {
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; }
}
}

3
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

Loading…
Cancel
Save