Browse Source

Support date.DayOfWeek

pull/14/head
sunkaixuan 3 years ago
parent
commit
18a0fe26b6
  1. 1
      Src/Asp.Net/SqlServerTest/UnitTest/UCustom011.cs
  2. 3
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/DateType.cs
  3. 26
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs

1
Src/Asp.Net/SqlServerTest/UnitTest/UCustom011.cs

@ -18,6 +18,7 @@ namespace OrmTest
var x2 = db.Queryable<Order>().Select(it => (DateTime.Now - SqlFunc.GetDate().AddDays(-1)).TotalHours).ToList(); var x2 = db.Queryable<Order>().Select(it => (DateTime.Now - SqlFunc.GetDate().AddDays(-1)).TotalHours).ToList();
var x3 = db.Queryable<Order>().Select(it => (DateTime.Now - SqlFunc.GetDate().AddHours(-1)).TotalMinutes).ToList(); var x3 = db.Queryable<Order>().Select(it => (DateTime.Now - SqlFunc.GetDate().AddHours(-1)).TotalMinutes).ToList();
var x4 = db.Queryable<Order>().Select(it => (DateTime.Now - SqlFunc.GetDate().AddMinutes(-1)).TotalSeconds).ToList(); var x4 = db.Queryable<Order>().Select(it => (DateTime.Now - SqlFunc.GetDate().AddMinutes(-1)).TotalSeconds).ToList();
var x5 = db.Queryable<Order>().Select(it =>it.CreateTime.DayOfWeek).ToList();
if (x1.Any()) if (x1.Any())
{ {
Check.Exception(x1.First()!=365, "unit error . UCustom011"); Check.Exception(x1.First()!=365, "unit error . UCustom011");

3
Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/DateType.cs

@ -14,6 +14,7 @@ namespace SqlSugar
Hour = 4, Hour = 4,
Second=5, Second=5,
Minute=6, Minute=6,
Millisecond=7 Millisecond=7,
Weekday=8
} }
} }

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

@ -23,6 +23,10 @@ namespace SqlSugar
else if (IsDateDiff(expression)) else if (IsDateDiff(expression))
{ {
ResolveDateDiff(parameter, isLeft, expression); ResolveDateDiff(parameter, isLeft, expression);
}
else if (expression.Member.Name== "DayOfWeek"&& expression.Type==typeof(DayOfWeek))
{
ResolveDayOfWeek(parameter, isLeft, expression);
} }
else if (isHasValue) else if (isHasValue)
{ {
@ -212,6 +216,28 @@ namespace SqlSugar
#endregion #endregion
#region Resolve special member #region Resolve special member
private void ResolveDayOfWeek(ExpressionParameter parameter, bool? isLeft, MemberExpression expression)
{
var exp = expression.Expression;
var value = GetNewExpressionValue(exp);
var result = this.Context.DbMehtods.DateValue(new MethodCallExpressionModel()
{
Args = new List<MethodCallExpressionArgs>() {
new MethodCallExpressionArgs(){
MemberName=value,
MemberValue=value
},
new MethodCallExpressionArgs(){
MemberName=DateType.Weekday,
MemberValue=DateType.Weekday
}
}
}); ;
base.AppendMember(parameter, isLeft, result);
}
private void ResolveDateDiff(ExpressionParameter parameter, bool? isLeft, MemberExpression expression) private void ResolveDateDiff(ExpressionParameter parameter, bool? isLeft, MemberExpression expression)
{ {
var binaryExp=expression.Expression as BinaryExpression; var binaryExp=expression.Expression as BinaryExpression;

Loading…
Cancel
Save