Synchronization code

This commit is contained in:
sunkaixuan 2023-04-28 18:26:54 +08:00
parent 66fc3358b5
commit 1618ed8bbb
3 changed files with 44 additions and 1 deletions

View File

@ -26,6 +26,12 @@ namespace SqlSugar
}
return dict;
}
public static bool ContainsMethodName(BinaryExpression expression, string name)
{
var visitor = new MethodCallExpressionVisitor(name);
var hasMethodCallWithName = visitor.HasMethodCallWithName(expression);
return hasMethodCallWithName;
}
public static bool IsVariable(Expression expr)
{
var ps = new ParameterExpressionVisitor();

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace SqlSugar
{
@ -17,4 +18,31 @@ namespace SqlSugar
return base.VisitParameter(node);
}
}
internal class MethodCallExpressionVisitor : ExpressionVisitor
{
private readonly string _methodName;
private bool _hasMethodCallWithName;
public MethodCallExpressionVisitor(string methodName)
{
_methodName = methodName;
}
public bool HasMethodCallWithName(Expression expression)
{
Visit(expression);
return _hasMethodCallWithName;
}
protected override Expression VisitMethodCall(MethodCallExpression node)
{
if (node.Method.Name.Contains(_methodName))
{
_hasMethodCallWithName = true;
return node;
}
return base.VisitMethodCall(node);
}
}
}

View File

@ -266,7 +266,16 @@ namespace SqlSugar
}
}
}
var selector = GetNewExpressionValue(rightExpression.Arguments[0]);
var selector = "";
bool hasMethodCallWithName = ExpressionTool.ContainsMethodName(expression, "Join");
if (hasMethodCallWithName)
{
selector = GetNewExpressionValue(rightExpression.Arguments[0], ResolveExpressType.WhereMultiple);
}
else
{
selector = GetNewExpressionValue(rightExpression.Arguments[0]);
}
var selectorExp = rightExpression.Arguments[0];
if (selector.Contains(".") && selectorExp is LambdaExpression)
{