diff --git a/Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs b/Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs index af498e4cb..84e6498e6 100644 --- a/Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs +++ b/Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs @@ -176,6 +176,7 @@ namespace OrmTest var test21 = db.Queryable().Where(it=>it.Id.ToString()==1.ToString()).Select(it => it.CreateTime.ToString("24")).First(); var test22 = db.Queryable().Where(it => it.Id.ToString() == 1.ToString()).Select(it => SqlFunc.AggregateDistinctCount(it.CreateTime)).First(); var test23 = db.Queryable().Where(it =>true).Select(it => new { x1 = it.CreateTime.ToString("yyyy-MM") ,it.CreateTime}).ToList(); + var test24 = db.Queryable().Where(it => true).Select(it => new { x1 = it.CreateTime.ToString("yyyy-MM-dd _ HH _ mm _ ss "), it.CreateTime }).ToList(); Console.WriteLine("#### Examples End ####"); } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs index ffd3f7ca3..dc004857e 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs +++ b/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() { parameter2, parameter } };