/// <summary> /// Visits a QueryExpression tree whose root node is the LinqSelectExpression. /// </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(LinqSelectExpression expression) { string source = this.ComputeUriInternal(expression.Source); LinqNewExpression newExpression = expression.Lambda.Body as LinqNewExpression; LinqNewInstanceExpression newInstanceExpression = expression.Lambda.Body as LinqNewInstanceExpression; QueryPropertyExpression propertyExpression = expression.Lambda.Body as QueryPropertyExpression; string select = string.Empty; if (propertyExpression != null) { return(string.Format(CultureInfo.InvariantCulture, "{0}/{1}", source, propertyExpression.Name)); } else if (newExpression != null) { select = this.ExpressionConverter.Convert(newExpression); this.SetSelectQueryOption(select); this.hasQueryOption = true; return(string.Format(CultureInfo.InvariantCulture, "{0}{1}", source, string.Empty)); } else if (newInstanceExpression != null) { select = this.ExpressionConverter.Convert(newInstanceExpression); this.SetSelectQueryOption(select); this.hasQueryOption = true; return(string.Format(CultureInfo.InvariantCulture, "{0}{1}", source, string.Empty)); } return(source); }
public override QueryExpression Visit(QueryPropertyExpression expression) { var pseudoLocalizedName = this.pseudoLocalizeFunc(expression.Name); var instance = this.ReplaceExpression(expression.Instance); return CommonQueryBuilder.Property(instance, pseudoLocalizedName); }
/// <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 virtual QueryExpression Visit(QueryPropertyExpression expression) { var instance = this.ResolvePropertyInstance(expression.Instance); // TODO: should we relax this? var instanceExpressionType = instance.GetExpressionTypeOrElementType(); var typeWithProperties = instanceExpressionType as IQueryTypeWithProperties; if (typeWithProperties == null) { var referenceType = instanceExpressionType as QueryReferenceType; if (referenceType != null) { typeWithProperties = referenceType.QueryEntityType as IQueryTypeWithProperties; } } if (typeWithProperties == null) { throw new TaupoArgumentException("Given expression must be of a query type with properties. Actual: " + instance.ExpressionType.GetType().Name + "."); } if (!typeWithProperties.Properties.Any(m => m.Name == expression.Name)) { throw new TaupoArgumentException("Given property was not found: " + expression.Name + "."); } var type = typeWithProperties.Properties.Single(m => m.Name == expression.Name).PropertyType; return(instance.Property(expression.Name, type)); }
public override QueryExpression Visit(QueryPropertyExpression expression) { var pseudoLocalizedName = this.pseudoLocalizeFunc(expression.Name); var instance = this.ReplaceExpression(expression.Instance); return(CommonQueryBuilder.Property(instance, pseudoLocalizedName)); }
/// <summary> /// Overrides the Visit expression and finds and analyzes property expressions to see if the KeyExpression is before /// If it is then this is an invalid query for the client /// </summary> /// <param name="expression">Expression to be analyzed</param> /// <returns>The same expression</returns> public override QueryExpression Visit(QueryPropertyExpression expression) { var keyExpression = expression.Instance as LinqToAstoriaKeyExpression; if (keyExpression != null) { this.InvalidClientQuery = true; } return(base.Visit(expression)); }
/// <summary> /// Replaces the given expression. /// </summary> /// <param name="expression">Expression to replace.</param> /// <returns>Replaced expression.</returns> public virtual QueryExpression Visit(QueryPropertyExpression expression) { QueryExpression instance = this.ReplaceExpression(expression.Instance); if (this.HasChanged(expression.Instance, instance)) { return(instance.Property(expression.Name, expression.ExpressionType)); } return(expression); }
/// <summary> /// Visits a QueryExpression tree whose root node is the QueryPropertyExpression. /// </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(QueryPropertyExpression expression) { var instanceString = this.ComputeUriInternal(expression.Instance); if (instanceString != null) { instanceString += "/"; } return(string.Format(CultureInfo.InvariantCulture, "{0}{1}", instanceString, expression.Name)); }
/// <summary> /// Visits a QueryExpression tree whose root node is the QueryPropertyExpression. /// </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(QueryPropertyExpression expression) { var instance = this.Convert(expression.Instance); if (string.IsNullOrEmpty(instance)) { return(string.Format(CultureInfo.InvariantCulture, "{0}", expression.Name)); } else { return(string.Format(CultureInfo.InvariantCulture, "{0}/{1}", instance, expression.Name)); } }
/// <summary> /// Replaces the given expression. /// </summary> /// <param name="expression">Expression to replace.</param> /// <returns> /// Replaced expression. /// </returns> public override QueryExpression Visit(QueryPropertyExpression expression) { // sub properties of scalar types do not get sent to the server // TODO: should this even include sub-properties of complex types? if (expression.Instance.ExpressionType is QueryScalarType) { return(base.Visit(expression)); } else { this.propertyExpressions.Add(expression); return(expression); } }
/// <summary> /// Evaluates the specified expression. /// </summary> /// <param name="expression">The expression to evaluate</param> /// <returns>Value of the expression</returns> public override QueryValue Visit(QueryPropertyExpression expression) { if (expression.ExpressionType is AstoriaQueryStreamType) { var originalSource = this.Evaluate(expression.Instance); var source = originalSource as QueryStructuralValue; return(source.GetValue(expression.Name)); } else { return(base.Visit(expression)); } }
/// <summary> /// Overrides the Visit expression and finds and analyzes property expressions to see if the KeyExpression is before /// If it is then this is an invalid query for the client /// </summary> /// <param name="expression">Expression to be analyzed</param> /// <returns>The same expression</returns> public override QueryExpression Visit(QueryPropertyExpression expression) { var keyExpression = expression.Instance as LinqToAstoriaKeyExpression; if (keyExpression == null) { // Also check if a KeyExpression followed by an As operator is before the current expression. var asExpression = expression.Instance as QueryAsExpression; if (asExpression != null) { keyExpression = asExpression.Source as LinqToAstoriaKeyExpression; } } if (keyExpression != null) { this.InvalidClientQuery = true; } return(base.Visit(expression)); }
/// <summary> /// Returns the expand string that represents the expression. /// </summary> /// <param name="lambdaExpression">The lambda expression to convert to an expand string.</param> /// <returns>String representation of the lambda expression.</returns> private static string ToExpandString(this QueryExpression lambdaExpression) { ExceptionUtilities.CheckArgumentNotNull(lambdaExpression, "lambdaExpression"); QueryPropertyExpression queryPropertyExpression = lambdaExpression as QueryPropertyExpression; ExceptionUtilities.CheckArgumentNotNull(queryPropertyExpression, "queryExpression as QueryPropertyExpression"); QueryAsExpression queryAsExpression = queryPropertyExpression.Instance as QueryAsExpression; if (queryAsExpression != null) { QueryEntityType queryEntityType = queryAsExpression.TypeToOperateAgainst as QueryEntityType; ExceptionUtilities.CheckObjectNotNull(queryEntityType, "The type to operate against for the query As expression is not a QueryEntityType"); return(queryEntityType.EntityType.FullName + "/" + queryPropertyExpression.Name); } else { return(queryPropertyExpression.Name); } }
/// <summary> /// Evaluates the specified expression. /// </summary> /// <param name="expression">The expression to evaluate.</param> /// <returns>Value of the expression.</returns> public virtual QueryValue Visit(QueryPropertyExpression expression) { var originalSource = this.Evaluate(expression.Instance); var sourceAsStructuralValue = originalSource as QueryStructuralValue; var sourceAsReferenceValue = originalSource as QueryReferenceValue; var sourceAsRecordValue = originalSource as QueryRecordValue; var sourceAsScalarValue = originalSource as QueryScalarValue; QueryValue result; if (sourceAsReferenceValue != null) { sourceAsStructuralValue = sourceAsReferenceValue.IsNull ? sourceAsReferenceValue.Type.QueryEntityType.NullValue : sourceAsReferenceValue.EntityValue; } if (sourceAsStructuralValue != null) { result = sourceAsStructuralValue.GetValue(expression.Name); } else if (sourceAsRecordValue != null) { var matchingMembers = sourceAsRecordValue.Type.Properties.Where(m => m.Name == expression.Name).ToList(); ExceptionUtilities.Assert(matchingMembers.Count == 1, "Expecting exactly one member with name '{0}'. Actual: {1}.", expression.Name, matchingMembers.Count); result = sourceAsRecordValue.GetMemberValue(sourceAsRecordValue.Type.Properties.IndexOf(matchingMembers[0])); } else { ExceptionUtilities.CheckObjectNotNull(sourceAsScalarValue, "Instance must evaluate to a structural or record or scalar value. Actual: '{0}'.", originalSource); ExceptionUtilities.Assert( sourceAsScalarValue.Type is IQueryTypeWithProperties, "Only query scalar types implementing IQueryTypeWithProperties are supported as query member property, actual type: {0}.", sourceAsScalarValue.Type.StringRepresentation); result = sourceAsScalarValue.Type.EvaluationStrategy.EvaluateMemberProperty(sourceAsScalarValue, expression.ExpressionType, expression.Name); } return(result); }
/// <summary> /// Visits a QueryExpression tree whose root node is the QueryPropertyExpression. /// </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(QueryPropertyExpression expression) { var instance = this.Convert(expression.Instance); if (string.IsNullOrEmpty(instance)) { return string.Format(CultureInfo.InvariantCulture, "{0}", expression.Name); } else { return string.Format(CultureInfo.InvariantCulture, "{0}/{1}", instance, expression.Name); } }
/// <summary> /// Overrides the Visit expression and finds and analyzes property expressions to see if the KeyExpression is before /// If it is then this is an invalid query for the client /// </summary> /// <param name="expression">Expression to be analyzed</param> /// <returns>The same expression</returns> public override QueryExpression Visit(QueryPropertyExpression expression) { var keyExpression = expression.Instance as LinqToAstoriaKeyExpression; if (keyExpression != null) { this.InvalidClientQuery = true; } return base.Visit(expression); }
/// <summary> /// Overrides the Visit expression and finds and analyzes property expressions to see if the KeyExpression is before /// If it is then this is an invalid query for the client /// </summary> /// <param name="expression">Expression to be analyzed</param> /// <returns>The same expression</returns> public override QueryExpression Visit(QueryPropertyExpression expression) { var keyExpression = expression.Instance as LinqToAstoriaKeyExpression; if (keyExpression == null) { // Also check if a KeyExpression followed by an As operator is before the current expression. var asExpression = expression.Instance as QueryAsExpression; if (asExpression != null) { keyExpression = asExpression.Source as LinqToAstoriaKeyExpression; } } if (keyExpression != null) { this.InvalidClientQuery = true; } return base.Visit(expression); }
/// <summary> /// Generates System.CodeDom.CodeExpression from the given expression. /// </summary> /// <param name="expression">Expression from which System.CodeDom.CodeExpression is generated.</param> /// <returns>Generated System.CodeDom.CodeExpression.</returns> public virtual CodeExpression Visit(QueryPropertyExpression expression) { CodeExpression instance = this.GenerateCode(expression.Instance); return(instance.Property(expression.Name)); }
/// <summary> /// Visits a QueryExpression tree whose root node is the QueryPropertyExpression. /// </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(QueryPropertyExpression expression) { var instanceString = this.ComputeUriInternal(expression.Instance); if (instanceString != null) { instanceString += "/"; } return string.Format(CultureInfo.InvariantCulture, "{0}{1}", instanceString, expression.Name); }
/// <summary> /// Visits a QueryExpression tree whose root node is the QueryPropertyExpression. /// </summary> /// <param name="expression">The root node of the expression tree being visited.</param> /// <returns>Uri query string representing the expression.</returns> public virtual string Visit(QueryPropertyExpression expression) { throw new TaupoNotSupportedException("Not supported"); }