Browse Source

Update exp to sql .Week

pull/14/head
sunkaixuan 3 years ago
parent
commit
d98ca10359
  1. 2
      Src/Asp.Net/SqlServerTest/UnitTest/UCustom011.cs
  2. 33
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

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

@ -18,7 +18,7 @@ namespace OrmTest
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 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();
var x5 = db.Queryable<Order>().Select(it => new { x = DateTime.Now.DayOfWeek.ToString() }).ToList();
if (x1.Any())
{
Check.Exception(x1.First()!=365, "unit error . UCustom011");

33
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

@ -559,6 +559,10 @@ namespace SqlSugar
{
parameter.CommonTempData = item.ToString();
}
else if (IsDateItemValue(item))
{
parameter.CommonTempData = GetNewExpressionValue(item);
}
else
{
base.Start();
@ -581,7 +585,7 @@ namespace SqlSugar
methodCallExpressionArgs.IsMember = false;
}
}
if (IsDateDate(item) || IsDateValue(item))
if (IsDateDate(item) || IsDateValue(item)|| IsDateItemValue(item))
{
methodCallExpressionArgs.IsMember = true;
}
@ -604,6 +608,33 @@ namespace SqlSugar
parameter.ChildExpression = null;
}
private bool IsDateItemValue(Expression item)
{
var result = false;
if (item is MemberExpression)
{
var memberExp = item as MemberExpression;
if (memberExp != null && memberExp.Expression != null && memberExp.Expression.Type == UtilConstants.DateType)
{
foreach (var dateType in UtilMethods.EnumToDictionary<DateType>())
{
if (memberExp.Member.Name.EqualCase(dateType.Key))
{
result = true;
break;
}
else if (memberExp.Member.Name=="DayOfWeek")
{
result = true;
break;
}
}
}
}
return result;
}
private static bool IsDateDate(Expression item)
{
return item.Type == UtilConstants.DateType && item is MemberExpression && (item as MemberExpression).Member.Name == "Date" && item.ToString() != "DateTime.Now.Date";

Loading…
Cancel
Save