Browse Source

Update exp to sql

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
de5d2cf881
  1. 2
      Src/Asp.Net/SqlServerTest/Demos/1_Query.cs
  2. 28
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs

2
Src/Asp.Net/SqlServerTest/Demos/1_Query.cs

@ -453,7 +453,9 @@ namespace OrmTest.Demo
var test51 = db.Queryable<Student>().Select(it=>new { x= SqlFunc.ToDate(it.CreateTime).Year+"-" }).ToList();
var test52 = db.Queryable<Student>().Select(it => SqlFunc.IsNull(it.CreateTime, SqlFunc.GetDate())).ToList();
var test53 = db.Queryable<Student>().Select(it => SqlFunc.IsNull(it.CreateTime, SqlFunc.GetDate())).First();
var test54 = db.Queryable<Student>().Where(it => it.CreateTime == test52.First().Value).ToList();
}
public static void Page()
{
var db = GetInstance();

28
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs

@ -32,11 +32,15 @@ namespace SqlSugar
{
ResolveValueBool(parameter, baseParameter, expression, isLeft, isSingle);
}
else if (isValue && expression.Expression != null && expression.Expression is MethodCallExpression)
{
ResolveCallValue(parameter, baseParameter, expression, isLeft, isSetTempData, isSingle);
}
else if (isValue)
{
ResolveValue(parameter, baseParameter, expression, isLeft, isSetTempData, isSingle);
}
else if (expression.Expression != null &&expression.Expression.Type==UtilConstants.DateType&&expression is MemberExpression && expression.Expression is MethodCallExpression)
else if (expression.Expression != null && expression.Expression.Type == UtilConstants.DateType && expression is MemberExpression && expression.Expression is MethodCallExpression)
{
ResolveDateDateByCall(parameter, isLeft, expression);
}
@ -193,6 +197,28 @@ namespace SqlSugar
}
}
}
private void ResolveCallValue(ExpressionParameter parameter, ExpressionParameter baseParameter, MemberExpression expression, bool? isLeft, bool isSetTempData, bool isSingle)
{
try
{
baseParameter.ChildExpression = expression;
string fieldName = string.Empty;
if (isSetTempData)
{
var value = ExpressionTool.DynamicInvoke(expression);
baseParameter.CommonTempData = value;
}
else
{
var value = ExpressionTool.DynamicInvoke(expression);
base.AppendValue(parameter, isLeft, value);
}
}
catch
{
Check.Exception(true, "Not Support {0}",expression.ToString());
}
}
private MemberExpression ResolveValue(ExpressionParameter parameter, ExpressionParameter baseParameter, MemberExpression expression, bool? isLeft, bool isSetTempData, bool isSingle)
{

Loading…
Cancel
Save