mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-18 17:48:11 +08:00
Add SqlFunc.ToTime
This commit is contained in:
@@ -70,6 +70,7 @@ namespace OrmTest.UnitTest
|
|||||||
Substring();
|
Substring();
|
||||||
Replace();
|
Replace();
|
||||||
Length();
|
Length();
|
||||||
|
Time();
|
||||||
}
|
}
|
||||||
base.End("Method Test");
|
base.End("Method Test");
|
||||||
}
|
}
|
||||||
@@ -111,6 +112,21 @@ namespace OrmTest.UnitTest
|
|||||||
}, "Length error");
|
}, "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()
|
private void Replace()
|
||||||
{
|
{
|
||||||
var x2 = Guid.NewGuid();
|
var x2 = Guid.NewGuid();
|
||||||
|
@@ -191,6 +191,12 @@ namespace SqlSugar
|
|||||||
return string.Format(" CAST({0} AS DATETIME)", parameter.MemberName);
|
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)
|
public virtual string ToDecimal(MethodCallExpressionModel model)
|
||||||
{
|
{
|
||||||
var parameter = model.Args[0];
|
var parameter = model.Args[0];
|
||||||
|
@@ -37,6 +37,7 @@ namespace SqlSugar
|
|||||||
string ToBool(MethodCallExpressionModel model);
|
string ToBool(MethodCallExpressionModel model);
|
||||||
string Substring(MethodCallExpressionModel model);
|
string Substring(MethodCallExpressionModel model);
|
||||||
string ToDate(MethodCallExpressionModel model);
|
string ToDate(MethodCallExpressionModel model);
|
||||||
|
string ToTime(MethodCallExpressionModel model);
|
||||||
string ToDecimal(MethodCallExpressionModel model);
|
string ToDecimal(MethodCallExpressionModel model);
|
||||||
string Length(MethodCallExpressionModel model);
|
string Length(MethodCallExpressionModel model);
|
||||||
string Replace(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 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 int ToInt32(object value) { return value.ObjToInt(); }
|
||||||
public static long ToInt64(object value) { return Convert.ToInt64(value); }
|
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(); }
|
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 string ToString(object value) { return value.ObjToString(); }
|
||||||
public static decimal ToDecimal(object value) { return value.ObjToDecimal(); }
|
public static decimal ToDecimal(object value) { return value.ObjToDecimal(); }
|
||||||
public static Guid ToGuid(object value) { return Guid.Parse(value.ObjToString()); }
|
public static Guid ToGuid(object value) { return Guid.Parse(value.ObjToString()); }
|
||||||
|
@@ -208,6 +208,8 @@ namespace SqlSugar
|
|||||||
return this.Context.DbMehtods.ToInt64(model);
|
return this.Context.DbMehtods.ToInt64(model);
|
||||||
case "ToDate":
|
case "ToDate":
|
||||||
return this.Context.DbMehtods.ToDate(model);
|
return this.Context.DbMehtods.ToDate(model);
|
||||||
|
case "ToTime":
|
||||||
|
return this.Context.DbMehtods.ToTime(model);
|
||||||
case "ToString":
|
case "ToString":
|
||||||
return this.Context.DbMehtods.ToString(model);
|
return this.Context.DbMehtods.ToString(model);
|
||||||
case "ToDecimal":
|
case "ToDecimal":
|
||||||
|
Reference in New Issue
Block a user