From 9ab46b31328ede827744a295f48c25a6d98d4bdc Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 13 Aug 2017 01:19:15 +0800 Subject: [PATCH] - --- Src/Asp.Net/SqlServerTest/Demos/1_Query.cs | 2 ++ Src/Asp.Net/SqlServerTest/Program.cs | 34 +++++++++---------- .../Method/DefaultDbMethod.cs | 2 +- .../ResolveItems/MemberExpressionResolve.cs | 23 +++++++++++-- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs b/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs index 27064880f..c5ee31aed 100644 --- a/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs +++ b/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs @@ -182,6 +182,8 @@ namespace OrmTest.Demo var getTodayList = db.Queryable().Where(it => SqlFunc.DateIsSame(it.CreateTime, DateTime.Now)).ToList(); var joinSql = db.Queryable("student", "s").OrderBy("id").Select("id,name").ToPageList(1, 2); + + var getDay1List = db.Queryable().Where(it=>it.CreateTime.Value.Hour==1).ToList(); } public static void Page() { diff --git a/Src/Asp.Net/SqlServerTest/Program.cs b/Src/Asp.Net/SqlServerTest/Program.cs index b73a61cca..34f4f3679 100644 --- a/Src/Asp.Net/SqlServerTest/Program.cs +++ b/Src/Asp.Net/SqlServerTest/Program.cs @@ -17,23 +17,23 @@ namespace OrmTest { static void Main(string[] args) { - // /***Unit Test***/ - new Select(1).Init(); - new Field(1).Init(); - new Where(1).Init(); - new Method(1).Init(); - new JoinQuery(1).Init(); - new SingleQuery(1).Init(); - new SelectQuery(1).Init(); - new AutoClose(1).Init(); - new Insert(1).Init(); - new Delete(1).Init(); - new Update(1).Init(); - new Mapping(1).Init(); - new DataTest(1).Init(); - new EnumTest(1).Init(); - /***Performance Test***/ - new SqlSugarPerformance(100).Select(); + //// /***Unit Test***/ + //new Select(1).Init(); + //new Field(1).Init(); + //new Where(1).Init(); + //new Method(1).Init(); + //new JoinQuery(1).Init(); + //new SingleQuery(1).Init(); + //new SelectQuery(1).Init(); + //new AutoClose(1).Init(); + //new Insert(1).Init(); + //new Delete(1).Init(); + //new Update(1).Init(); + //new Mapping(1).Init(); + //new DataTest(1).Init(); + //new EnumTest(1).Init(); + ///***Performance Test***/ + //new SqlSugarPerformance(100).Select(); /***Demo***/ OrmTest.Demo.Query.Init(); diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs index db3578889..edda2caa2 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs @@ -153,7 +153,7 @@ namespace SqlSugar { var parameter = model.Args[0]; var parameter2 = model.Args[1]; - return string.Format(" ({0}({1})) ", parameter2.MemberName, parameter.MemberName); + return string.Format(" DateName({0},{1}) ", parameter2.MemberName, parameter.MemberName); } public virtual string ToInt32(MethodCallExpressionModel model) diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs index bafbec3ac..8bc90186c 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs @@ -18,14 +18,15 @@ namespace SqlSugar var isBool = expression.Type == PubConst.BoolType; var isValueBool = isValue && isBool && parameter.BaseExpression == null; var isLength = expression.Member.Name == "Length" && (expression.Expression as MemberExpression).Type == PubConst.StringType; + var isDateValue = expression.Member.Name.IsIn(Enum.GetNames(typeof(DateType))) && (expression.Expression as MemberExpression).Type == PubConst.DateType; if (isLength) { var oldCommonTempDate = parameter.CommonTempData; parameter.CommonTempData = CommonTempDataType.Result; this.Expression = expression.Expression; - var isConst=this.Expression is ConstantExpression; + var isConst = this.Expression is ConstantExpression; this.Start(); - var methodParamter = new MethodCallExpressionArgs() { IsMember = !isConst, MemberName = parameter.CommonTempData, MemberValue = null }; + var methodParamter = new MethodCallExpressionArgs() { IsMember = !isConst, MemberName = parameter.CommonTempData, MemberValue = null }; var result = this.Context.DbMehtods.Length(new MethodCallExpressionModel() { Args = new List() { @@ -36,6 +37,24 @@ namespace SqlSugar parameter.CommonTempData = oldCommonTempDate; return; } + else if (isDateValue) { + var name = expression.Member.Name; + var oldCommonTempDate = parameter.CommonTempData; + parameter.CommonTempData = CommonTempDataType.Result; + this.Expression = expression.Expression; + var isConst = this.Expression is ConstantExpression; + 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); + parameter.CommonTempData = oldCommonTempDate; + return; + } else if (isValueBool) { isValue = false;