Browse Source

Optimized code (Subquery.Group)

pull/33/head
sunkaixuan 2 years ago
parent
commit
aee4fd562b
  1. 24
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs
  2. 8
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs

24
Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs

@ -9,6 +9,30 @@ namespace SqlSugar
{
public class ExpressionTool
{
public static List<string> GetTopLevelMethodCalls(Expression expression)
{
var methodCalls = new List<string>();
GetTopLevelMethodCalls(expression, methodCalls);
return methodCalls;
}
public static void GetTopLevelMethodCalls(Expression expression, List<string> methodCalls)
{
if (expression is MethodCallExpression methodCallExpression)
{
methodCalls.Add(methodCallExpression.Method.Name);
if (methodCallExpression.Object is MethodCallExpression parentMethodCallExpression)
{
GetTopLevelMethodCalls(parentMethodCallExpression, methodCalls);
}
}
else if (expression is LambdaExpression lambdaExpression)
{
GetTopLevelMethodCalls(lambdaExpression.Body, methodCalls);
}
}
public static Dictionary<string, Expression> GetNewExpressionItemList(Expression lamExp)
{
var caseExp = GetLambdaExpressionBody(lamExp);

8
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs

@ -327,15 +327,15 @@ namespace SqlSugar
{
return false;
}
var methodString = method.ToString();
if (methodString.IndexOf("GroupBy(")<=0)
var topMethods =ExpressionTool.GetTopLevelMethodCalls(method);
if (!topMethods.Contains("Subqueryable"))
{
return false;
}
if (Regex.Matches(methodString, @"Subqueryable\(").Count!=1)
if (!topMethods.Contains("GroupBy"))
{
return false;
}
}
return true;
}
private static bool IsJoinString(BinaryExpression expression, string operatorValue)

Loading…
Cancel
Save