mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-30 04:45:54 +08:00
Add SqlFunc.ToTime
This commit is contained in:
parent
f8c5aef4c5
commit
8d5b8a717d
@ -70,6 +70,7 @@ namespace OrmTest.UnitTest
|
||||
Substring();
|
||||
Replace();
|
||||
Length();
|
||||
Time();
|
||||
}
|
||||
base.End("Method Test");
|
||||
}
|
||||
@ -111,6 +112,21 @@ namespace OrmTest.UnitTest
|
||||
}, "Length error");
|
||||
}
|
||||
|
||||
|
||||
private void Time()
|
||||
{
|
||||
TimeSpan s = TimeSpan.Parse("11:22:22");
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.ToTime("11:12:59")==s;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(CAST(@MethodConst0 AS TIME) = @Const1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","11:12:59"),new SugarParameter("@Const1",s)
|
||||
}, "Time error");
|
||||
}
|
||||
|
||||
|
||||
private void Replace()
|
||||
{
|
||||
var x2 = Guid.NewGuid();
|
||||
|
@ -191,6 +191,12 @@ namespace SqlSugar
|
||||
return string.Format(" CAST({0} AS DATETIME)", parameter.MemberName);
|
||||
}
|
||||
|
||||
public virtual string ToTime(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
return string.Format(" CAST({0} AS TIME)", parameter.MemberName);
|
||||
}
|
||||
|
||||
public virtual string ToDecimal(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
|
@ -37,6 +37,7 @@ namespace SqlSugar
|
||||
string ToBool(MethodCallExpressionModel model);
|
||||
string Substring(MethodCallExpressionModel model);
|
||||
string ToDate(MethodCallExpressionModel model);
|
||||
string ToTime(MethodCallExpressionModel model);
|
||||
string ToDecimal(MethodCallExpressionModel model);
|
||||
string Length(MethodCallExpressionModel model);
|
||||
string Replace(MethodCallExpressionModel model);
|
||||
|
@ -69,7 +69,18 @@ namespace SqlSugar
|
||||
public static TResult IIF<TResult>(bool Expression, TResult thenValue, TResult elseValue) { throw new NotSupportedException("This method is not supported by the current parameter"); }
|
||||
public static int ToInt32(object value) { return value.ObjToInt(); }
|
||||
public static long ToInt64(object value) { return Convert.ToInt64(value); }
|
||||
/// <summary>
|
||||
/// yyyy-MM-dd HH:mm:ss.fff
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static DateTime ToDate(object value) { return value.ObjToDate(); }
|
||||
/// <summary>
|
||||
///HH:mm:ss
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static TimeSpan ToTime(object value) { throw new NotSupportedException("This method is not supported by the current parameter"); }
|
||||
public static string ToString(object value) { return value.ObjToString(); }
|
||||
public static decimal ToDecimal(object value) { return value.ObjToDecimal(); }
|
||||
public static Guid ToGuid(object value) { return Guid.Parse(value.ObjToString()); }
|
||||
|
@ -208,6 +208,8 @@ namespace SqlSugar
|
||||
return this.Context.DbMehtods.ToInt64(model);
|
||||
case "ToDate":
|
||||
return this.Context.DbMehtods.ToDate(model);
|
||||
case "ToTime":
|
||||
return this.Context.DbMehtods.ToTime(model);
|
||||
case "ToString":
|
||||
return this.Context.DbMehtods.ToString(model);
|
||||
case "ToDecimal":
|
||||
|
Loading…
Reference in New Issue
Block a user