public void VisitUnknownNonExtensionExpression_Ignored() { var expression = new UnknownExpression(typeof(object)); var result = SubQueryFindingExpressionTreeVisitor.Process(expression, _methodInfoBasedNodeTypeRegistry); Assert.That(result, Is.SameAs(expression)); }
public void TreeWithNoSubquery() { Expression expression = Expression.Constant("test"); Expression newExpression = SubQueryFindingExpressionTreeVisitor.Process(expression, _methodInfoBasedNodeTypeRegistry); Assert.That(newExpression, Is.SameAs(expression)); }
private Expression ProcessArgumentExpression(Expression argumentExpression) { // First, convert the argument expressions to their actual values - this unwraps ConstantantExpressions and UnaryExpressions var convertedParameters = UnwrapArgumentExpression(argumentExpression); // Then, detect subqueries var parametersWithSubQueriesDetected = SubQueryFindingExpressionTreeVisitor.Process(convertedParameters, _nodeTypeProvider); return(parametersWithSubQueriesDetected); }
public void VisitExtensionExpression_ChildrenAreEvaluated() { var subQuery = ExpressionHelper.MakeExpression(() => (from s in ExpressionHelper.CreateQueryable <Cook> () select s).Any()); var extensionExpression = new VBStringComparisonExpression(subQuery, true); // evaluate the ExpressionHelper.CreateQueryable<Cook> () method var inputExpression = PartialEvaluatingExpressionTreeVisitor.EvaluateIndependentSubtrees(extensionExpression); var result = SubQueryFindingExpressionTreeVisitor.Process(inputExpression, _methodInfoBasedNodeTypeRegistry); Assert.That(((VBStringComparisonExpression)result).Comparison, Is.TypeOf(typeof(SubQueryExpression))); }
public void VisitorUsesExpressionTreeVisitor_ToGetPotentialQueryOperator() { _methodInfoBasedNodeTypeRegistry.Register(new[] { typeof(QueryableFakeWithCount <>).GetMethod("get_Count") }, typeof(CountExpressionNode)); Expression subQuery = ExpressionHelper.MakeExpression(() => new QueryableFakeWithCount <int>().Count); Expression surroundingExpression = Expression.Lambda(subQuery); var newLambdaExpression = (LambdaExpression)SubQueryFindingExpressionTreeVisitor.Process(surroundingExpression, _methodInfoBasedNodeTypeRegistry); Assert.That(newLambdaExpression.Body, Is.InstanceOf(typeof(SubQueryExpression))); }
public void VisitorUsesNodeTypeRegistry_ToParseAndAnalyzeSubQueries() { Expression subQuery = ExpressionHelper.MakeExpression(() => CustomSelect(ExpressionHelper.CreateQueryable <Cook>(), s => s)); Expression surroundingExpression = Expression.Lambda(subQuery); // evaluate the ExpressionHelper.CreateQueryable<Cook> () method var inputExpression = PartialEvaluatingExpressionTreeVisitor.EvaluateIndependentSubtrees(surroundingExpression); var emptyNodeTypeRegistry = new MethodInfoBasedNodeTypeRegistry(); emptyNodeTypeRegistry.Register(new[] { ((MethodCallExpression)subQuery).Method }, typeof(SelectExpressionNode)); var newLambdaExpression = (LambdaExpression)SubQueryFindingExpressionTreeVisitor.Process(inputExpression, emptyNodeTypeRegistry); Assert.That(newLambdaExpression.Body, Is.InstanceOf(typeof(SubQueryExpression))); }
private IExpressionNode ParseNonQueryOperatorExpression(Expression expression, string associatedIdentifier) { var preprocessedExpression = SubQueryFindingExpressionTreeVisitor.Process(expression, _nodeTypeProvider); try { return(new MainSourceExpressionNode(associatedIdentifier, preprocessedExpression)); } catch (ArgumentTypeException ex) { var message = String.Format( "Cannot parse expression '{0}' as it has an unsupported type. Only query sources (that is, expressions that implement IEnumerable) " + "and query operators can be parsed.", preprocessedExpression); throw new ParserException(message, ex); } }
public void TreeWithSubquery() { Expression subQuery = SelectTestQueryGenerator.CreateSimpleQuery(ExpressionHelper.CreateQueryable <Cook>()).Expression; Expression surroundingExpression = Expression.Lambda(subQuery); Expression newExpression = SubQueryFindingExpressionTreeVisitor.Process(surroundingExpression, _methodInfoBasedNodeTypeRegistry); Assert.That(newExpression, Is.Not.SameAs(surroundingExpression)); Assert.That(newExpression, Is.InstanceOf(typeof(LambdaExpression))); var newLambdaExpression = (LambdaExpression)newExpression; Assert.That(newLambdaExpression.Body, Is.InstanceOf(typeof(SubQueryExpression))); var newSubQueryExpression = (SubQueryExpression)newLambdaExpression.Body; Assert.That( ((QuerySourceReferenceExpression)newSubQueryExpression.QueryModel.SelectClause.Selector).ReferencedQuerySource, Is.SameAs(newSubQueryExpression.QueryModel.MainFromClause)); }
private IExpressionNode ParseNonQueryOperatorExpression(Expression expression, string associatedIdentifier) { var preprocessedExpression = SubQueryFindingExpressionTreeVisitor.Process(expression, _nodeTypeProvider); try { // Assertions to ensure the argument exception can only happen because of an unsupported type in expression. Assertion.IsNotNull(expression); Assertion.IsFalse(string.IsNullOrEmpty(associatedIdentifier)); return(new MainSourceExpressionNode(associatedIdentifier, preprocessedExpression)); } catch (ArgumentException ex) { var message = string.Format( "Cannot parse expression '{0}' as it has an unsupported type. Only query sources (that is, expressions that implement IEnumerable) " + "and query operators can be parsed.", FormattingExpressionTreeVisitor.Format(preprocessedExpression)); throw new NotSupportedException(message, ex); } }