Browse Source

Strengthen RowSum RowMax RowCount RowMin

pull/40/head
sunkaixuan 1 year ago
parent
commit
6d17e41e5b
  1. 22
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  2. 20
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs

22
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs

@ -23,22 +23,42 @@ namespace SqlSugar
}
public virtual string RowCount(MethodCallExpressionModel model)
{
if (model.Args.Count > 1)
{
return $"count({model.Args[0].MemberName}) over( partition by {model.Args[2].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')} order by {model.Args[1].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')})";
}
return "count(1) over()";
}
public string RowSum(MethodCallExpressionModel model)
{
return "SUM(" + model.Args[0].MemberName +") over()";
if (model.Args.Count > 1)
{
return $"SUM({model.Args[0].MemberName}) over( partition by {model.Args[2].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')} order by {model.Args[1].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')})";
}
return "SUM(" + model.Args[0].MemberName +") over()";
}
public string RowAvg(MethodCallExpressionModel model)
{
if (model.Args.Count > 1)
{
return $"AVG({model.Args[0].MemberName}) over( partition by {model.Args[2].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')} order by {model.Args[1].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')})";
}
return "AVG(" + model.Args[0].MemberName + ") over()";
}
public string RowMin(MethodCallExpressionModel model)
{
if (model.Args.Count > 1)
{
return $"Min({model.Args[0].MemberName}) over( partition by {model.Args[2].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')} order by {model.Args[1].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')})";
}
return "Min(" + model.Args[0].MemberName + ") over()";
}
public string RowMax(MethodCallExpressionModel model)
{
if (model.Args.Count > 1)
{
return $"Max({model.Args[0].MemberName}) over( partition by {model.Args[2].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')} order by {model.Args[1].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')})";
}
return "Max(" + model.Args[0].MemberName + ") over()";
}
public virtual string IIF(MethodCallExpressionModel model)

20
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs

@ -37,6 +37,10 @@ namespace SqlSugar
{
throw new NotSupportedException("Can only be used in expressions");
}
public static int RowCount(object countFiledName,object orderByField, object partitionBy)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static int RowCount()
{
throw new NotSupportedException("Can only be used in expressions");
@ -45,18 +49,34 @@ namespace SqlSugar
{
throw new NotSupportedException("Can only be used in expressions");
}
public static TRestult RowSum<TRestult>(TRestult filedName, object orderByField, object partitionBy)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static TRestult RowMax<TRestult>(TRestult filedName)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static TRestult RowMax<TRestult>(TRestult filedNameobject,object orderByField, object partitionBy)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static TRestult RowMin<TRestult>(TRestult filedName)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static TRestult RowMin<TRestult>(TRestult filedName, object orderByField, object partitionBy)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static TRestult RowAvg<TRestult>(TRestult filedName)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static TRestult RowAvg<TRestult>(TRestult filedName, object orderByField, object partitionBy)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static string JsonField(object json,string fieldName)
{
throw new NotSupportedException("Can only be used in expressions");

Loading…
Cancel
Save