diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs index 73094e2cb..ff70269ce 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs @@ -8,6 +8,21 @@ namespace SqlSugar { public partial class DefaultDbMethod : IDbMethods { + public virtual string RowNumber(MethodCallExpressionModel model) + { + if (model.Args.Count == 1) + { + return $"row_number() over(order by {model.Args[0].MemberName})"; + } + else + { + return $"row_number() over( partition by {model.Args[1].MemberName} order by {model.Args[0].MemberName})"; + } + } + public virtual string RowCount(MethodCallExpressionModel model) + { + return "count(1) over()"; + } public virtual string IIF(MethodCallExpressionModel model) { var parameter = model.Args[0]; diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs index cd0bb6dd2..6202f239c 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs @@ -87,6 +87,9 @@ namespace SqlSugar string Asc(MethodCallExpressionModel model); string Desc(MethodCallExpressionModel model); string Stuff(MethodCallExpressionModel model); + string RowNumber(MethodCallExpressionModel model); + string RowCount(MethodCallExpressionModel model); + string GetDateString(string dateValue,string format); string GetForXmlPath(); } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs index c39192d82..b6d5a9270 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs @@ -9,6 +9,18 @@ namespace SqlSugar { public partial class SqlFunc { + public static int RowNumber(object orderByField, object partitionBy) + { + throw new NotSupportedException("Can only be used in expressions"); + } + public static int RowNumber(object orderByField) + { + throw new NotSupportedException("Can only be used in expressions"); + } + public static int RowCount() + { + throw new NotSupportedException("Can only be used in expressions"); + } public static T Desc(T value) { throw new NotSupportedException("Can only be used in expressions"); diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs index 55a83a530..9ac44dbf4 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs @@ -1010,6 +1010,10 @@ namespace SqlSugar return this.Context.DbMehtods.Desc(model); case "Stuff": return this.Context.DbMehtods.Stuff(model); + case "RowNumber": + return this.Context.DbMehtods.RowNumber(model); + case "RowCount": + return this.Context.DbMehtods.RowCount(model); default: break; }