Expression Dictionary BUG

This commit is contained in:
sunkaixuan
2017-06-27 16:25:36 +08:00
parent 8b25e950f3
commit 366006af96
3 changed files with 24 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ namespace OrmTest.UnitTest
base.Begin();
for (int i = 0; i < base.Count; i++)
{
whereSingle16();
whereSingle15();
whereSingle1();
whereSingle2();
@@ -264,6 +265,21 @@ namespace OrmTest.UnitTest
new SugarParameter("@Const0",1)
}, "whereSingle15");
}
private void whereSingle16()
{
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("key", "x1");
Expression<Func<DataTestInfo, bool>> exp = it => it.String == dic["key"];
ExpressionContext expContext = new ExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "( [String] = @Const0 )", new List<SugarParameter>()
{
new SugarParameter("@Const0",dic["key"])
}, "whereSingle16");
}
}
public class WhereConst

View File

@@ -158,7 +158,7 @@ namespace SqlSugar
return reval;
}
public static object DynamicInvoke(MemberExpression expression)
public static object DynamicInvoke(Expression expression)
{
object value = Expression.Lambda(expression).Compile().DynamicInvoke();
if (value != null && value.GetType().IsClass && value.GetType() != ExpressionConst.StringType)

View File

@@ -14,6 +14,13 @@ namespace SqlSugar
var express = base.Expression as MethodCallExpression;
var isLeft = parameter.IsLeft;
string methodName = express.Method.Name;
if (methodName == "get_Item") {
string paramterName =this.Context.SqlParameterKeyWord+ExpressionConst.Const + this.Context.ParameterIndex;
this.Context.Parameters.Add(new SugarParameter(paramterName, ExpressionTool.DynamicInvoke(express)));
this.Context.Result.Append(string.Format(" {0} ",paramterName));
this.Context.ParameterIndex++;
return;
}
var isValidNativeMethod = MethodMapping.ContainsKey(methodName)&&express.Method.DeclaringType.Namespace==("System");
if (!isValidNativeMethod&&express.Method.DeclaringType.Namespace.IsIn("System.Linq", "System.Collections.Generic")&&methodName=="Contains") {
methodName = "ContainsArray";