Browse Source

Update exp to sql

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
03fc0cd9f8
  1. 1
      Src/Asp.Net/SqlServerTest/Demos/1_Query.cs
  2. 8
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

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

@ -451,6 +451,7 @@ namespace OrmTest.Demo
var test49 = db.Queryable<Student>().Where(it => it.CreateTime != null).Where(it => SqlFunc.ToDate(it.CreateTime).Year == DateTime.Now.Year).ToList(); var test49 = db.Queryable<Student>().Where(it => it.CreateTime != null).Where(it => SqlFunc.ToDate(it.CreateTime).Year == DateTime.Now.Year).ToList();
var test50 = db.Queryable<Student>().Where(it => it.CreateTime != null).Where(it => SqlFunc.ToDate(it.CreateTime).Year == SqlFunc.GetDate().Year).ToList(); var test50 = db.Queryable<Student>().Where(it => it.CreateTime != null).Where(it => SqlFunc.ToDate(it.CreateTime).Year == SqlFunc.GetDate().Year).ToList();
var test51 = db.Queryable<Student>().Select(it=>new { x= SqlFunc.ToDate(it.CreateTime).Year+"-" }).ToList(); 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();
} }
public static void Page() public static void Page()
{ {

8
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

@ -422,7 +422,13 @@ namespace SqlSugar
methodCallExpressionArgs.IsMember = false; methodCallExpressionArgs.IsMember = false;
} }
} }
if (methodCallExpressionArgs.IsMember == false) if (methodCallExpressionArgs.IsMember == false&&(item is MethodCallExpression&&item.ToString()== "GetDate()") || (item is UnaryExpression && ((UnaryExpression)item).Operand.ToString() == "GetDate()")) {
var parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.MethodConst + this.Context.ParameterIndex;
this.Context.ParameterIndex++;
methodCallExpressionArgs.MemberName = value;
methodCallExpressionArgs.MemberValue = null;
}
else if (methodCallExpressionArgs.IsMember == false)
{ {
var parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.MethodConst + this.Context.ParameterIndex; var parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.MethodConst + this.Context.ParameterIndex;
this.Context.ParameterIndex++; this.Context.ParameterIndex++;

Loading…
Cancel
Save