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. 9
      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 getSingleOrDefault = db.Queryable<Student>().Where(it => it.Id == 1).Single();
var getFirstOrDefault = db.Queryable<Student>().First(); var getFirstOrDefault = db.Queryable<Student>().First();
var getByWhere = db.Queryable<Student>().Where(it => it.Id == 1 || it.Name == "a").ToList(); 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 getByFuns = db.Queryable<Student>().Where(it => SqlFunc.IsNullOrEmpty(it.Name)).ToList();
var sum = db.Queryable<Student>().Select(it => it.SchoolId).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); var sum2 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id).Sum((st, sc) => sc.Id);

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

@ -214,6 +214,14 @@ namespace SqlSugar
parameter.CommonTempData = CommonTempDataType.Result; parameter.CommonTempData = CommonTempDataType.Result;
this.Expression = expression.Expression; this.Expression = expression.Expression;
var isConst = this.Expression is ConstantExpression; var isConst = this.Expression is ConstantExpression;
if (this.Expression.Type == UtilConstants.DateType && this.Expression.ToString() == "DateTime.Now")
{
this.Expression = expression;
var parameterName=base.AppendParameter(ExpressionTool.GetMemberValue(expression.Member, expression));
base.AppendMember(parameter, isLeft, parameterName);
}
else
{
this.Start(); this.Start();
var result = this.Context.DbMehtods.DateValue(new MethodCallExpressionModel() var result = this.Context.DbMehtods.DateValue(new MethodCallExpressionModel()
{ {
@ -223,6 +231,7 @@ namespace SqlSugar
} }
}); });
base.AppendMember(parameter, isLeft, result); base.AppendMember(parameter, isLeft, result);
}
parameter.CommonTempData = oldCommonTempDate; parameter.CommonTempData = oldCommonTempDate;
} }

Loading…
Cancel
Save