Browse Source

Add SqlFunc.toDateShort

pull/1/head
skx 4 years ago
parent
commit
a65b3b7583
  1. 6
      Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs
  2. 6
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  3. 1
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs
  4. 1
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs
  5. 2
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs
  6. 6
      Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteExpressionContext.cs
  7. 9
      Src/Asp.Net/SqliteTest/Demo/Demo1_Queryable.cs

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

@ -135,7 +135,11 @@ namespace OrmTest
Id = SqlFunc.AggregateSum(SqlFunc.IF(it.Id > 0).Return(1).End(0))
}).ToList();
var list2 = db.Queryable<Order>().Select(it => new
{
date = SqlFunc.ToDateShort(it.CreateTime),
datetime = SqlFunc.ToDate(it.CreateTime)
}).ToList();
Console.WriteLine("#### SqlFunc End ####");
}

6
Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs

@ -252,6 +252,12 @@ namespace SqlSugar
return string.Format(" CAST({0} AS DATETIME)", parameter.MemberName);
}
public virtual string ToDateShort(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS DATE)", parameter.MemberName);
}
public virtual string ToTime(MethodCallExpressionModel model)
{
var parameter = model.Args[0];

1
Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs

@ -42,6 +42,7 @@ namespace SqlSugar
string CaseWhen(List<KeyValuePair<string,string>> sqls);
string Substring(MethodCallExpressionModel model);
string ToDate(MethodCallExpressionModel model);
string ToDateShort(MethodCallExpressionModel model);
string ToTime(MethodCallExpressionModel model);
string ToDecimal(MethodCallExpressionModel model);
string Length(MethodCallExpressionModel model);

1
Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs

@ -98,6 +98,7 @@ namespace SqlSugar
/// <param name="value"></param>
/// <returns></returns>
public static DateTime ToDate(object value) { return value.ObjToDate(); }
public static DateTime ToDateShort(object value) { return value.ObjToDate(); }
/// <summary>
///HH:mm:ss
/// </summary>

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

@ -668,6 +668,8 @@ namespace SqlSugar
return this.Context.DbMehtods.BitwiseAnd(model);
case "BitwiseInclusiveOR":
return this.Context.DbMehtods.BitwiseInclusiveOR(model);
case "ToDateShort":
return this.Context.DbMehtods.ToDateShort(model);
default:
break;
}

6
Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteExpressionContext.cs

@ -97,6 +97,12 @@ namespace SqlSugar
return string.Format(" DATETIME({0})", parameter.MemberName);
}
public override string ToDateShort(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" strftime('%Y-%m-%d', {0})", parameter.MemberName);
}
public override string DateAddDay(MethodCallExpressionModel model)
{
var parameter = model.Args[0];

9
Src/Asp.Net/SqliteTest/Demo/Demo1_Queryable.cs

@ -124,7 +124,16 @@ namespace OrmTest
Console.WriteLine("#### SqlFunc Start ####");
var db = GetInstance();
var index= db.Queryable<Order>().Select(it => SqlFunc.Contains("a", "cccacc")).First();
var list2 = db.Queryable<Order>().Select(it => new
{
date = SqlFunc.ToDateShort(it.CreateTime),
datetime = SqlFunc.ToDate(it.CreateTime)
}).ToList();
var list3 = db.Queryable<Order>().Select(it => new Order
{
CreateTime = SqlFunc.ToDateShort(it.CreateTime)
}).ToList();
Console.WriteLine("#### SqlFunc End ####");
}

Loading…
Cancel
Save