Browse Source

Optimized SqlServer Date format

pull/14/head
sunkaixuan 3 years ago
parent
commit
68b230a790
  1. 1
      Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs
  2. 4
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

1
Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs

@ -176,6 +176,7 @@ namespace OrmTest
var test21 = db.Queryable<Order>().Where(it=>it.Id.ToString()==1.ToString()).Select(it => it.CreateTime.ToString("24")).First();
var test22 = db.Queryable<Order>().Where(it => it.Id.ToString() == 1.ToString()).Select(it => SqlFunc.AggregateDistinctCount(it.CreateTime)).First();
var test23 = db.Queryable<Order>().Where(it =>true).Select(it => new { x1 = it.CreateTime.ToString("yyyy-MM") ,it.CreateTime}).ToList();
var test24 = db.Queryable<Order>().Where(it => true).Select(it => new { x1 = it.CreateTime.ToString("yyyy-MM-dd _ HH _ mm _ ss "), it.CreateTime }).ToList();
Console.WriteLine("#### Examples End ####");
}

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

@ -1006,6 +1006,10 @@ namespace SqlSugar
{
return string.Format("CONVERT(varchar(100),convert(datetime,{0}), {1})", value, formatString);
}
else if (IsSqlServer())
{
return string.Format("FORMAT({0},'{1}','en-US')", value, formatString);
}
var parameter = new MethodCallExpressionArgs() { IsMember = true, MemberValue = DateType.Year };
var parameter2 = new MethodCallExpressionArgs() { IsMember = true, MemberName = value };
var parameters = new MethodCallExpressionModel() { Args = new List<MethodCallExpressionArgs>() { parameter2, parameter } };

Loading…
Cancel
Save