public override Expression Visit(Expression node) { if (node != null && !_insideThenBy && IsQueryableResult(node) && _mutator.IsEntityType(node.Type.GetGenericArguments()[0])) { FoundExpressions.Add(node); } return(base.Visit(node)); }
protected override Expression VisitMethodCall(MethodCallExpression node) { // can't handle string overloads = need type information to construct Expression calls. if (node != null && (node.Method.MethodIsClosedFormOf(IncludeMethodInfo) || node.Method.MethodIsClosedFormOf(ThenIncludeReferenceMethodInfo) || node.Method.MethodIsClosedFormOf(ThenIncludeCollectionMethodInfo))) { FoundExpressions.Add(node); // need to short-circuit on ThenInclude, if we inject include before, it could change the IIncludeQueryable type that this ThenInclude is expecting if (node.Method.Name == nameof(EntityFrameworkQueryableExtensions.ThenInclude)) { return(node); } } return(base.VisitMethodCall(node)); }
public override Expression Visit(Expression expression) { if (expression is MethodCallExpression methodCallExpression && (methodCallExpression.Method.Name == "ThenInclude" || methodCallExpression.Method.Name == "ThenBy" || methodCallExpression.Method.Name == "ThenByDescending" || methodCallExpression.Method.Name == "Skip" || methodCallExpression.Method.Name == "Take")) { return(expression); } if (expression != null && IsQueryableResult(expression)) { FoundExpressions.Add(expression); } return(base.Visit(expression)); }
public override Expression Visit(Expression expression) { // can't inject OrderBy inside of include - would have to rewrite the ThenInclude method to one that accepts ordered input var insideThenInclude = default(bool?); if (expression is MethodCallExpression methodCallExpression && (methodCallExpression.Method.Name == "ThenInclude" || methodCallExpression.Method.Name == "ThenBy" || methodCallExpression.Method.Name == "ThenByDescending")) { insideThenInclude = _insideThenInclude; _insideThenInclude = true; } if (!_insideThenInclude && expression != null && IsQueryableResult(expression) && !FoundExpressions.ContainsKey(expression)) { var validProperties = GetValidPropertiesForOrderBy(expression); validProperties = _mutator.FilterPropertyInfos(expression.Type.GetGenericArguments()[0], validProperties); if (validProperties.Any()) { FoundExpressions.Add(expression, validProperties); } } try { return(base.Visit(expression)); } finally { _insideThenInclude = insideThenInclude ?? _insideThenInclude; } }