Browse Source

DateTime.Now.XXX Expression bug

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
69b284da70
  1. 1
      Src/Asp.Net/SqlServerTest/Demos/1_Query.cs
  2. 19
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs

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

@ -252,6 +252,7 @@ namespace OrmTest.Demo
var getSingleOrDefault = db.Queryable<Student>().Where(it => it.Id == 1).Single();
var getFirstOrDefault = db.Queryable<Student>().First();
var getByWhere = db.Queryable<Student>().Where(it => it.Id == 1 || it.Name == "a").ToList();
var getByWhere2 = db.Queryable<Student>().Where(it => it.Id ==DateTime.Now.Year).ToList();
var getByFuns = db.Queryable<Student>().Where(it => SqlFunc.IsNullOrEmpty(it.Name)).ToList();
var sum = db.Queryable<Student>().Select(it => it.SchoolId).ToList();
var sum2 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id).Sum((st, sc) => sc.Id);

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

@ -214,15 +214,24 @@ namespace SqlSugar
parameter.CommonTempData = CommonTempDataType.Result;
this.Expression = expression.Expression;
var isConst = this.Expression is ConstantExpression;
this.Start();
var result = this.Context.DbMehtods.DateValue(new MethodCallExpressionModel()
if (this.Expression.Type == UtilConstants.DateType && this.Expression.ToString() == "DateTime.Now")
{
Args = new List<MethodCallExpressionArgs>() {
this.Expression = expression;
var parameterName=base.AppendParameter(ExpressionTool.GetMemberValue(expression.Member, expression));
base.AppendMember(parameter, isLeft, parameterName);
}
else
{
this.Start();
var result = this.Context.DbMehtods.DateValue(new MethodCallExpressionModel()
{
Args = new List<MethodCallExpressionArgs>() {
new MethodCallExpressionArgs() { IsMember = !isConst, MemberName = parameter.CommonTempData, MemberValue = null },
new MethodCallExpressionArgs() { IsMember = true, MemberName = name, MemberValue = name }
}
});
base.AppendMember(parameter, isLeft, result);
});
base.AppendMember(parameter, isLeft, result);
}
parameter.CommonTempData = oldCommonTempDate;
}

Loading…
Cancel
Save