Add Sqlfunc.ToVarchar

This commit is contained in:
skx 2020-05-25 18:27:16 +08:00
parent 98130e7692
commit a52aad2da9
4 changed files with 10 additions and 0 deletions

View File

@ -401,5 +401,11 @@ namespace SqlSugar
{
return string.Format("CHARINDEX ({0},{1})", model.Args[0].MemberName, model.Args[1].MemberName);
}
public string ToVarchar(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS VARCHAR(MAX))", parameter.MemberName);
}
}
}

View File

@ -34,6 +34,7 @@ namespace SqlSugar
string ToInt32(MethodCallExpressionModel model);
string ToInt64(MethodCallExpressionModel model);
string ToString(MethodCallExpressionModel model);
string ToVarchar(MethodCallExpressionModel model);
string ToGuid(MethodCallExpressionModel model);
string ToDouble(MethodCallExpressionModel model);
string ToBool(MethodCallExpressionModel model);

View File

@ -101,6 +101,7 @@ namespace SqlSugar
/// <returns></returns>
public static TimeSpan ToTime(object value) { throw new NotSupportedException("Can only be used in expressions"); }
public static string ToString(object value) { return value.ObjToString(); }
public static string ToVarchar(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()); }
public static double ToDouble(object value) { return value.ObjToMoney(); }

View File

@ -611,6 +611,8 @@ namespace SqlSugar
}
Check.Exception(model.Args.Count > 1, "ToString (Format) is not supported, Use ToString().If time formatting can be used it.Date.Year+\"-\"+it.Data.Month+\"-\"+it.Date.Day ");
return this.Context.DbMehtods.ToString(model);
case "ToVarchar":
return this.Context.DbMehtods.ToVarchar(model);
case "ToDecimal":
return this.Context.DbMehtods.ToDecimal(model);
case "ToGuid":