Ejemplo n.º 1
0
        /// <summary>
        /// Retrieves the LINQ expression that backs this ObjectQuery for external consumption.
        /// It is important that the work to wrap the expression in an appropriate MergeAs call
        /// takes place in this method and NOT in ObjectQueryState.TryGetExpression which allows
        /// the unmodified expression (that does not include the MergeOption-preserving MergeAs call)
        /// to be retrieved and processed by the ELinq ExpressionConverter.
        /// </summary>
        /// <returns>
        ///   The LINQ expression for this ObjectQuery, wrapped in a MergeOption-preserving call
        ///   to the MergeAs method if the ObjectQuery.MergeOption property has been set.
        /// </returns>
        internal override Expression GetExpression()
        {
            // If this ObjectQuery is not backed by a LINQ Expression (it is an ESQL query),
            // then create a ConstantExpression that uses this ObjectQuery as its value.
            Expression retExpr;

            if (!this.QueryState.TryGetExpression(out retExpr))
            {
                retExpr = Expression.Constant(this);
            }

            Type objectQueryType = typeof(ObjectQuery <T>);

            if (this.QueryState.UserSpecifiedMergeOption.HasValue)
            {
                MethodInfo mergeAsMethod = objectQueryType.GetMethod("MergeAs", BindingFlags.Instance | BindingFlags.NonPublic);
                Debug.Assert(mergeAsMethod != null, "Could not retrieve ObjectQuery<T>.MergeAs method using reflection?");
                retExpr = TypeSystem.EnsureType(retExpr, objectQueryType);
                retExpr = Expression.Call(retExpr, mergeAsMethod, Expression.Constant(this.QueryState.UserSpecifiedMergeOption.Value));
            }

            if (null != this.QueryState.Span)
            {
                MethodInfo includeSpanMethod = objectQueryType.GetMethod("IncludeSpan", BindingFlags.Instance | BindingFlags.NonPublic);
                Debug.Assert(includeSpanMethod != null, "Could not retrieve ObjectQuery<T>.IncludeSpan method using reflection?");
                retExpr = TypeSystem.EnsureType(retExpr, objectQueryType);
                retExpr = Expression.Call(retExpr, includeSpanMethod, Expression.Constant(this.QueryState.Span));
            }

            return(retExpr);
        }
Ejemplo n.º 2
0
        // <summary>
        // Retrieves the LINQ expression that backs this ObjectQuery for external consumption.
        // It is important that the work to wrap the expression in an appropriate MergeAs call
        // takes place in this method and NOT in ObjectQueryState.TryGetExpression which allows
        // the unmodified expression (that does not include the MergeOption-preserving MergeAs call)
        // to be retrieved and processed by the ELinq ExpressionConverter.
        // </summary>
        // <returns> The LINQ expression for this ObjectQuery, wrapped in a MergeOption-preserving call to the MergeAs method if the ObjectQuery.MergeOption property has been set. </returns>
        internal override Expression GetExpression()
        {
            // If this ObjectQuery is not backed by a LINQ Expression (it is an ESQL query),
            // then create a ConstantExpression that uses this ObjectQuery as its value.
            Expression retExpr;

            if (!QueryState.TryGetExpression(out retExpr))
            {
                retExpr = Expression.Constant(this);
            }

            if (QueryState.UserSpecifiedMergeOption.HasValue)
            {
                retExpr = TypeSystem.EnsureType(retExpr, typeof(ObjectQuery <T>));
                retExpr = Expression.Call(retExpr, MergeAsMethod, Expression.Constant(QueryState.UserSpecifiedMergeOption.Value));
            }

            if (null != QueryState.Span)
            {
                retExpr = TypeSystem.EnsureType(retExpr, typeof(ObjectQuery <T>));
                retExpr = Expression.Call(retExpr, IncludeSpanMethod, Expression.Constant(QueryState.Span));
            }

            return(retExpr);
        }
        internal override Expression GetExpression()
        {
            Expression expression;

            if (!this.QueryState.TryGetExpression(out expression))
            {
                expression = (Expression)Expression.Constant((object)this);
            }
            if (this.QueryState.UserSpecifiedMergeOption.HasValue)
            {
                expression = (Expression)Expression.Call(TypeSystem.EnsureType(expression, typeof(ObjectQuery <T>)), ObjectQuery <T> .MergeAsMethod, (Expression)Expression.Constant((object)this.QueryState.UserSpecifiedMergeOption.Value));
            }
            if (this.QueryState.Span != null)
            {
                expression = (Expression)Expression.Call(TypeSystem.EnsureType(expression, typeof(ObjectQuery <T>)), ObjectQuery <T> .IncludeSpanMethod, (Expression)Expression.Constant((object)this.QueryState.Span));
            }
            return(expression);
        }