Browse Source

Add SqlFunc.ToTime

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
8d5b8a717d
  1. 16
      Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Method.cs
  2. 6
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs
  3. 1
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Method/IDbMethods.cs
  4. 11
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Method/SqlFunc.cs
  5. 2
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

16
Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Method.cs

@ -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();

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

@ -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];

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

@ -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);

11
Src/Asp.Net/SqlSugar/ExpressionsToSql/Method/SqlFunc.cs

@ -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()); }

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

@ -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…
Cancel
Save