/// <summary> /// Replaces the given expression. /// </summary> /// <param name="expression">The root node of the expression tree being visited.</param> /// <returns>Replaced expression.</returns> public virtual QueryExpression Visit(LinqNewExpression expression) { QueryExpression[] members = expression.Members.Select(this.ReplaceExpression).ToArray(); if (HasChanged(expression.Members, members)) { return(LinqBuilder.New(expression.MemberNames, members, expression.ExpressionType)); } return(expression); }
/// <summary> /// Resolves types for the specified expression. /// </summary> /// <param name="expression">The expression to resolve types for.</param> /// <returns>Expression with resolved types.</returns> public QueryExpression Visit(LinqNewExpression expression) { var members = expression.Members.Select(this.ResolveTypes).ToList(); var type = new QueryAnonymousStructuralType(this.EvaluationStrategy); for (int i = 0; i < members.Count; i++) { type.Add(QueryProperty.Create(expression.MemberNames[i], members[i].ExpressionType)); } return(LinqBuilder.New(expression.MemberNames, members, type)); }
/// <summary> /// Replaces the given expression. /// </summary> /// <param name="expression">The root node of the expression tree being visited.</param> /// <returns> /// Replaced expression. /// </returns> public override QueryExpression Visit(LinqSelectExpression expression) { // in a select, only properties will be sent this.propertyExpressions.Clear(); expression.Lambda.Accept(this); if (this.propertyExpressions.Count == 0) { return(expression.Source); } var newExpression = LinqBuilder.New(this.propertyExpressions.Select(p => this.IdentifierGenerator.GenerateIdentifier("temp")), this.propertyExpressions); var lambda = LinqBuilder.Lambda(newExpression, expression.Lambda.Parameters.ToArray()); return(expression.Source.Select(lambda)); }
/// <summary> /// Gets the existing values of the given primitive properties using the in-memory query evaluator /// </summary> /// <param name="set">The entity set</param> /// <param name="propertyNames">The properties to get values for</param> /// <returns>The values for the given properties as returned by the query evaluator</returns> protected internal Dictionary <string, List <object> > GetExistingPrimitivePropertyValues(EntitySet set, IEnumerable <string> propertyNames) { // build a projection query to find the values for the key properties var query = this.BuildRootQueryForSet(set).Select(o => LinqBuilder.New(propertyNames, propertyNames.Select(p => o.Property(p)))); // evaluate the projection var collection = this.Evaluator.Evaluate(query) as QueryCollectionValue; ExceptionUtilities.CheckObjectNotNull(collection, "Query did not return a collection: {0}", query); ExceptionUtilities.Assert(collection.EvaluationError == null, "Query evaluation error: " + collection.EvaluationError); var structuralValues = collection.Elements.Cast <QueryStructuralValue>(); var existingValues = propertyNames .ToDictionary(p => p, p => structuralValues.Select(v => v.GetScalarValue(p).Value).ToList()); return(existingValues); }
/// <summary> /// Visits a QueryExpression tree whose root node is the LinqNewInstanceExpression. /// </summary> /// <param name="expression">The root node of the expression tree being visited.</param> /// <returns>Uri query string representing the expression.</returns> public override string Visit(LinqNewInstanceExpression expression) { return(this.Convert(LinqBuilder.New(expression.MemberNames, expression.Members))); }