protected override Expression VisitMethodCall(MethodCallExpression expression)
            {
                if (expression.Instance == null &&
                    expression.Method.Name == "Include" &&
                    expression.Method.DeclaringType.Type == typeof(Remote.Linq.DynamicQuery.QueryFunctions) &&
                    expression.Method.GenericArgumentTypes.Count == 1 &&
                    expression.Arguments.Count == 2)
                {
                    var elementType = expression.Method.GenericArgumentTypes.Single().Type;

                    var queryableExpression = expression.Arguments[0];
                    var pathExpression      = expression.Arguments[1];

                    var efIncludeMethod = QueryableIncludeMethod.MakeGenericMethod(elementType);

                    var callExpression = new MethodCallExpression(null, efIncludeMethod, new[] { queryableExpression, pathExpression });
                    expression = callExpression;
                }

                return(base.VisitMethodCall(expression));
            }
Beispiel #2
0
            protected override Expression VisitMethodCall(MethodCallExpression node)
            {
                if (node.Instance is null &&
                    string.Equals(node.Method?.Name, nameof(QueryFunctions.Include), StringComparison.Ordinal) &&
                    node.Method?.DeclaringType?.Type == typeof(QueryFunctions) &&
                    node.Method?.GenericArgumentTypes?.Count == 1 &&
                    node.Arguments?.Count == 2)
                {
                    var elementType = node.Method.GenericArgumentTypes.Single().Type;

                    var queryableExpression = node.Arguments[0];
                    var pathExpression      = node.Arguments[1];

                    var efIncludeMethod = QueryableIncludeMethod.MakeGenericMethod(elementType);

                    var callExpression = new MethodCallExpression(null, efIncludeMethod, new[] { queryableExpression, pathExpression });
                    node = callExpression;
                }

                return(base.VisitMethodCall(node));
            }