mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
Add SqlFunc.toDateShort
This commit is contained in:
parent
98fef17e27
commit
a65b3b7583
@ -135,7 +135,11 @@ namespace OrmTest
|
|||||||
|
|
||||||
Id = SqlFunc.AggregateSum(SqlFunc.IF(it.Id > 0).Return(1).End(0))
|
Id = SqlFunc.AggregateSum(SqlFunc.IF(it.Id > 0).Return(1).End(0))
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
var list2 = db.Queryable<Order>().Select(it => new
|
||||||
|
{
|
||||||
|
date = SqlFunc.ToDateShort(it.CreateTime),
|
||||||
|
datetime = SqlFunc.ToDate(it.CreateTime)
|
||||||
|
}).ToList();
|
||||||
Console.WriteLine("#### SqlFunc End ####");
|
Console.WriteLine("#### SqlFunc End ####");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,6 +252,12 @@ namespace SqlSugar
|
|||||||
return string.Format(" CAST({0} AS DATETIME)", parameter.MemberName);
|
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)
|
public virtual string ToTime(MethodCallExpressionModel model)
|
||||||
{
|
{
|
||||||
var parameter = model.Args[0];
|
var parameter = model.Args[0];
|
||||||
|
@ -42,6 +42,7 @@ namespace SqlSugar
|
|||||||
string CaseWhen(List<KeyValuePair<string,string>> sqls);
|
string CaseWhen(List<KeyValuePair<string,string>> sqls);
|
||||||
string Substring(MethodCallExpressionModel model);
|
string Substring(MethodCallExpressionModel model);
|
||||||
string ToDate(MethodCallExpressionModel model);
|
string ToDate(MethodCallExpressionModel model);
|
||||||
|
string ToDateShort(MethodCallExpressionModel model);
|
||||||
string ToTime(MethodCallExpressionModel model);
|
string ToTime(MethodCallExpressionModel model);
|
||||||
string ToDecimal(MethodCallExpressionModel model);
|
string ToDecimal(MethodCallExpressionModel model);
|
||||||
string Length(MethodCallExpressionModel model);
|
string Length(MethodCallExpressionModel model);
|
||||||
|
@ -98,6 +98,7 @@ namespace SqlSugar
|
|||||||
/// <param name="value"></param>
|
/// <param name="value"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static DateTime ToDate(object value) { return value.ObjToDate(); }
|
public static DateTime ToDate(object value) { return value.ObjToDate(); }
|
||||||
|
public static DateTime ToDateShort(object value) { return value.ObjToDate(); }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///HH:mm:ss
|
///HH:mm:ss
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -668,6 +668,8 @@ namespace SqlSugar
|
|||||||
return this.Context.DbMehtods.BitwiseAnd(model);
|
return this.Context.DbMehtods.BitwiseAnd(model);
|
||||||
case "BitwiseInclusiveOR":
|
case "BitwiseInclusiveOR":
|
||||||
return this.Context.DbMehtods.BitwiseInclusiveOR(model);
|
return this.Context.DbMehtods.BitwiseInclusiveOR(model);
|
||||||
|
case "ToDateShort":
|
||||||
|
return this.Context.DbMehtods.ToDateShort(model);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,12 @@ namespace SqlSugar
|
|||||||
return string.Format(" DATETIME({0})", parameter.MemberName);
|
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)
|
public override string DateAddDay(MethodCallExpressionModel model)
|
||||||
{
|
{
|
||||||
var parameter = model.Args[0];
|
var parameter = model.Args[0];
|
||||||
|
@ -124,7 +124,16 @@ namespace OrmTest
|
|||||||
Console.WriteLine("#### SqlFunc Start ####");
|
Console.WriteLine("#### SqlFunc Start ####");
|
||||||
var db = GetInstance();
|
var db = GetInstance();
|
||||||
var index= db.Queryable<Order>().Select(it => SqlFunc.Contains("a", "cccacc")).First();
|
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 ####");
|
Console.WriteLine("#### SqlFunc End ####");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user