From f7c8191d27c812114688f59d4b07a9954126c031 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 13 Aug 2017 02:07:10 +0800 Subject: [PATCH] Update Demo --- Src/Asp.Net/MySqlTest/Demos/1_Query.cs | 4 ++++ .../MySqlTest/UnitTest/ExpressionTest/Method.cs | 14 ++++++-------- .../MySql/SqlBuilder/MySqlExpressionContext.cs | 8 +++++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Src/Asp.Net/MySqlTest/Demos/1_Query.cs b/Src/Asp.Net/MySqlTest/Demos/1_Query.cs index 0e1654dfe..75d8fa232 100644 --- a/Src/Asp.Net/MySqlTest/Demos/1_Query.cs +++ b/Src/Asp.Net/MySqlTest/Demos/1_Query.cs @@ -181,6 +181,10 @@ namespace OrmTest.Demo var getTodayList = db.Queryable().Where(it => SqlFunc.DateIsSame(it.CreateTime, DateTime.Now)).ToList(); var unionAll = db.UnionAll(db.Queryable(),db.Queryable()); + + var getDay1List = db.Queryable().Where(it => it.CreateTime.Value.Hour == 1).ToList(); + var getDateAdd = db.Queryable().Where(it => it.CreateTime.Value.AddDays(1) == DateTime.Now).ToList(); + var getDateIsSame = db.Queryable().Where(it => SqlFunc.DateIsSame(DateTime.Now, DateTime.Now, DateType.Hour)).ToList(); } public static void Page() { diff --git a/Src/Asp.Net/MySqlTest/UnitTest/ExpressionTest/Method.cs b/Src/Asp.Net/MySqlTest/UnitTest/ExpressionTest/Method.cs index 8fa6f7b38..226881671 100644 --- a/Src/Asp.Net/MySqlTest/UnitTest/ExpressionTest/Method.cs +++ b/Src/Asp.Net/MySqlTest/UnitTest/ExpressionTest/Method.cs @@ -272,8 +272,8 @@ namespace OrmTest.UnitTest expContext.Resolve(exp, ResolveExpressType.WhereSingle); var value = expContext.Result.GetString(); var pars = expContext.Parameters; - base.Check(value, pars, " ((@MethodConst1(@MethodConst0)) = @Const2 ) ", new List() { - new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",DateType.Year),new SugarParameter("@Const2",1) + base.Check(value, pars, " (Year(@MethodConst0) = @Const2 ) ", new List() { + new SugarParameter("@MethodConst0",x2),new SugarParameter("@Const2",1) }, "DateValue error"); } @@ -319,9 +319,8 @@ namespace OrmTest.UnitTest expContext.Resolve(exp, ResolveExpressType.WhereSingle); var value = expContext.Result.GetString(); var pars = expContext.Parameters; - base.Check(value, pars, "((DATE_ADD(@MethodConst1 INTERVAL @MethodConst2 @MethodConst0)) = @Const3 )", new List() { - new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",11),new SugarParameter("@Const3",x2), - new SugarParameter("@MethodConst2",DateType.Millisecond) + base.Check(value, pars, "((DATE_ADD(@MethodConst0 , INTERVAL @MethodConst1 Millisecond)) = @Const3 )", new List() { + new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",11),new SugarParameter("@Const3",x2) }, "DateAddByType error"); } private void DateAddDay() @@ -345,9 +344,8 @@ namespace OrmTest.UnitTest expContext.Resolve(exp, ResolveExpressType.WhereSingle); var value = expContext.Result.GetString(); var pars = expContext.Parameters; - base.Check(value, pars, " (TIMESTAMPDIFF(@MethodConst2,@MethodConst0,@MethodConst1)=0) ", new List() { - new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",x2), - new SugarParameter("@MethodConst2",DateType.Millisecond) + base.Check(value, pars, " (TIMESTAMPDIFF(Millisecond,@MethodConst0,@MethodConst1)=0) ", new List() { + new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",x2) }, "DateIsSameByType error"); } private void DateIsSameByDay() diff --git a/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs b/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs index 4dd6c55cc..93fb76c90 100644 --- a/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs +++ b/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs @@ -54,6 +54,12 @@ namespace SqlSugar } public class MySqlMethod : DefaultDbMethod, IDbMethods { + public override string DateValue(MethodCallExpressionModel model) + { + var parameter = model.Args[0]; + var parameter2 = model.Args[1]; + return string.Format(" {0}({1}) ", parameter2.MemberValue, parameter.MemberName); + } public override string Contains(MethodCallExpressionModel model) { @@ -96,7 +102,7 @@ namespace SqlSugar var parameter = model.Args[0]; var parameter2 = model.Args[1]; var parameter3 = model.Args[2]; - return string.Format(" (DATE_ADD({1} INTERVAL {2} {0})) ", parameter.MemberName, parameter2.MemberName, parameter3.MemberValue); + return string.Format(" (DATE_ADD({1} , INTERVAL {2} {0})) ", parameter3.MemberValue, parameter.MemberName, parameter2.MemberName); } public override string DateAddDay(MethodCallExpressionModel model)