diff --git a/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs b/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs index 196e60088..88aa07f66 100644 --- a/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs +++ b/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs @@ -252,6 +252,7 @@ namespace OrmTest.Demo var getSingleOrDefault = db.Queryable().Where(it => it.Id == 1).Single(); var getFirstOrDefault = db.Queryable().First(); var getByWhere = db.Queryable().Where(it => it.Id == 1 || it.Name == "a").ToList(); + var getByWhere2 = db.Queryable().Where(it => it.Id ==DateTime.Now.Year).ToList(); var getByFuns = db.Queryable().Where(it => SqlFunc.IsNullOrEmpty(it.Name)).ToList(); var sum = db.Queryable().Select(it => it.SchoolId).ToList(); var sum2 = db.Queryable((st, sc) => st.SchoolId == sc.Id).Sum((st, sc) => sc.Id); diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs index 5caa0bbac..782126956 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs +++ b/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() { + 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() { 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; }