Add Sqlfunc.Abs Sqlfunc.Round

This commit is contained in:
sunkaixuna 2021-09-04 09:26:02 +08:00
parent d2c3907b5f
commit b0db25a094
4 changed files with 23 additions and 0 deletions

View File

@ -477,5 +477,17 @@ namespace SqlSugar
var array = model.Args.Skip(1).Select(it => it.IsMember?it.MemberName:it.MemberValue).ToArray();
return string.Format("'"+str+ "'", array);
}
public string Abs(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" ABS({0}) ", parameter.MemberName);
}
public string Round(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" ROUND({0},{1}) ", parameter.MemberName);
}
}
}

View File

@ -73,5 +73,7 @@ namespace SqlSugar
string Oracle_ToChar(MethodCallExpressionModel model);
string SqlServer_DateDiff(MethodCallExpressionModel model);
string Format(MethodCallExpressionModel model);
string Abs(MethodCallExpressionModel model);
string Round(MethodCallExpressionModel model);
}
}

View File

@ -130,6 +130,11 @@ namespace SqlSugar
public static TResult GetSelfAndAutoFill<TResult>(TResult value) { throw new NotSupportedException("Can only be used in expressions"); }
public static DateTime GetDate() { throw new NotSupportedException("Can only be used in expressions"); }
public static string GetRandom() { throw new NotSupportedException("Can only be used in expressions"); }
public static T Abs<T>( T value) { throw new NotSupportedException("Can only be used in expressions"); }
public static string Round<T>(T value,int precision) { throw new NotSupportedException("Can only be used in expressions"); }
/// <summary>
/// Subquery
/// </summary>

View File

@ -789,6 +789,10 @@ namespace SqlSugar
var result = this.Context.DbMehtods.Format(model);
this.Context.Parameters.RemoveAll(it => model.Args.Select(x=>x.MemberName.ObjToString()).Contains(it.ParameterName) );
return result;
case "Abs":
return this.Context.DbMehtods.Abs(model);
case "Round":
return this.Context.DbMehtods.Round(model);
default:
break;
}