예제 #1
0
        /// <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(LinqToAstoriaKeyExpression expression)
        {
            var source = this.ResolveTypes(expression.Source);

            // rebuild the key in case any of the properties or values were unresolved
            return(source.Key(expression.KeyProperties.Select(pair => new NamedValue(pair.Key.Name, pair.Value.ScalarValue.Value))));
        }
예제 #2
0
        private LinqToAstoriaKeyExpression ResolveKeyExpressionForProperty(LinqToAstoriaKeyExpression keyExpression)
        {
            keyExpression = (LinqToAstoriaKeyExpression)this.ResolveTypes(keyExpression);
            var instanceType = this.GetInstanceTypeFromKeyExpression(keyExpression);

            return(new LinqToAstoriaKeyExpression(keyExpression.Source, keyExpression.KeyProperties, instanceType));
        }
예제 #3
0
            /// <summary>
            /// Visits a LinqKeyExpression.
            /// </summary>
            /// <param name="expression">The expression.</param>
            /// <returns>The result of visiting this expression.</returns>
            public CodeExpression Visit(LinqToAstoriaKeyExpression expression)
            {
                CodeExpression source = this.GenerateQueryCode(expression.Source).Expression;

                var lambda = this.GenerateQueryCode(expression.Lambda).Expression as CodeLambdaExpression;

                return(source.Call("Where", lambda));
            }
예제 #4
0
        /// <summary>
        /// Visits a QueryExpression tree whose root node is the LinqToAstoriaKeyExpression.
        /// </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(LinqToAstoriaKeyExpression expression)
        {
            ExceptionUtilities.CheckArgumentNotNull(expression, "expression");

            string        source  = this.ComputeUriInternal(expression.Source);
            StringBuilder builder = new StringBuilder();

            builder.Append(source);
            this.LiteralConverter.AppendKeyExpression(builder, expression.KeyProperties.Select(p => new NamedValue(p.Key.Name, p.Value.ScalarValue.Value)));
            return(builder.ToString());
        }
예제 #5
0
        private QueryStructuralType GetInstanceTypeFromKeyExpression(LinqToAstoriaKeyExpression keyExpression)
        {
            var collectionType = keyExpression.ExpressionType as QueryCollectionType;

            ExceptionUtilities.CheckObjectNotNull(collectionType, "Key expression type was not a collection type. Type was: {0}", keyExpression.ExpressionType);

            var instanceType = collectionType.ElementType as QueryStructuralType;

            ExceptionUtilities.CheckObjectNotNull(instanceType, "Collection element type was not a structural type. Type was: {0}", collectionType.ElementType);

            return(instanceType);
        }
예제 #6
0
        /// <summary>
        /// Visits a QueryExpression tree whose root node is the LinqKeyExpression.
        /// </summary>
        /// <param name="expression">The root node of the expression tree being visited.</param>
        /// <returns>Replaced expression.</returns>
        public virtual QueryExpression Visit(LinqToAstoriaKeyExpression expression)
        {
            QueryExpression source = this.ReplaceExpression(expression.Source);

            if (HasChanged(expression.Source, source))
            {
                return(LinqToAstoriaLinqBuilder.Key(source, expression.KeyProperties));
            }
            else
            {
                return(expression);
            }
        }
예제 #7
0
            /// <summary>
            /// Visits a LinqKeyExpression.
            /// </summary>
            /// <param name="expression">The expression.</param>
            /// <returns>The result of visiting this expression.</returns>
            public Expression Visit(LinqToAstoriaKeyExpression expression)
            {
                Expression source    = this.GenerateLinqExpression(expression.Source);
                Expression predicate = this.GenerateLinqExpression(expression.Lambda);

                Type sourceTypeArgument = this.GetSourceCollectionTypeArgument(source);

                var result = Expression.Call(typeof(Queryable), "Where", new Type[] { sourceTypeArgument }, source, predicate);

                if (!(expression.ExpressionType is QueryCollectionType))
                {
                    result = Expression.Call(typeof(Queryable), "SingleOrDefault", new Type[] { sourceTypeArgument }, result);
                }

                return(result);
            }
예제 #8
0
            /// <summary>
            /// Visits a LinqKeyExpression.
            /// </summary>
            /// <param name="expression">The expression.</param>
            /// <returns>Value of the expression</returns>
            public QueryValue Visit(LinqToAstoriaKeyExpression expression)
            {
                ExceptionUtilities.CheckArgumentNotNull(expression, "expression");

                var collectionType = expression.ExpressionType as QueryCollectionType;
                var replaced       = expression.Source.Where(expression.Lambda);

                if (collectionType != null)
                {
                    replaced = replaced.OfType(collectionType.ElementType);
                }
                else
                {
                    replaced = replaced.SingleOrDefault().As(expression.ExpressionType);
                }

                return(this.Evaluate(replaced));
            }
예제 #9
0
        /// <summary>
        /// Visits a QueryExpression tree whose root node is the LinqToAstoriaKeyExpression.
        /// </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(LinqToAstoriaKeyExpression expression)
        {
            ExceptionUtilities.CheckArgumentNotNull(expression, "expression");

            string source = this.ComputeUriInternal(expression.Source);
            StringBuilder builder = new StringBuilder();
            builder.Append(source);
            this.LiteralConverter.AppendKeyExpression(builder, expression.KeyProperties.Select(p => new NamedValue(p.Key.Name, p.Value.ScalarValue.Value)));
            return builder.ToString();
        }
예제 #10
0
 /// <summary>
 /// Visits a QueryExpression tree whose root node is the LinqToAstoriaKeyExpression.
 /// </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(LinqToAstoriaKeyExpression expression)
 {
     throw new TaupoNotSupportedException("Not supported");
 }
예제 #11
0
            /// <summary>
            /// Visits a LinqKeyExpression.
            /// </summary>
            /// <param name="expression">The expression.</param>
            /// <returns>The result of visiting this expression.</returns>
            public CodeExpression Visit(LinqToAstoriaKeyExpression expression)
            {
                CodeExpression source = this.GenerateQueryCode(expression.Source).Expression;

                var prm             = expression.Lambda.Parameters.Single();
                var codeQuerySource = source as CodeQueryExpression;

                string inputParameterName = this.GetInputParameterName(codeQuerySource);
                string groupParameterName = this.GetGroupParameterName(codeQuerySource);

                var newPrm = new CodeParameterDeclarationExpression();

                newPrm = new CodeParameterDeclarationExpression(new CodeImplicitTypeReference(), inputParameterName);
                this.ParameterNamesDictionary.Add(prm, newPrm);

                CodeLambdaExpression lambda;

                try
                {
                    lambda = (CodeLambdaExpression)this.GenerateCode(expression.Lambda);
                }
                finally
                {
                    this.ParameterNamesDictionary.Remove(prm);
                }

                if (codeQuerySource != null)
                {
                    if (codeQuerySource.Select == null && codeQuerySource.Where == null)
                    {
                        return(new CodeQueryExpression(
                                   inputParameterName,
                                   groupParameterName,
                                   codeQuerySource.From,
                                   lambda.Body,
                                   codeQuerySource.OrderByKeySelectors,
                                   codeQuerySource.AreDescending,
                                   codeQuerySource.GroupByKeySelector,
                                   codeQuerySource.Select));
                    }
                    else if (codeQuerySource.Select == null && codeQuerySource.Where != null)
                    {
                        return(new CodeQueryExpression(
                                   inputParameterName,
                                   groupParameterName,
                                   codeQuerySource.From,
                                   codeQuerySource.Where.BooleanAnd(lambda.Body),
                                   codeQuerySource.OrderByKeySelectors,
                                   codeQuerySource.AreDescending,
                                   codeQuerySource.GroupByKeySelector,
                                   codeQuerySource.Select));
                    }
                    else
                    {
                        return(new CodeQueryExpression(
                                   inputParameterName,
                                   groupParameterName,
                                   codeQuerySource,
                                   lambda.Body,
                                   Enumerable.Empty <CodeExpression>(),
                                   Enumerable.Empty <bool>(),
                                   null,
                                   null));
                    }
                }
                else
                {
                    return(new CodeQueryExpression(
                               inputParameterName,
                               groupParameterName,
                               source,
                               lambda.Body,
                               Enumerable.Empty <CodeExpression>(),
                               Enumerable.Empty <bool>(),
                               null,
                               null));
                }
            }