/// <summary>
        /// Visits a <see cref="FirstOperator" /> and coalesces it with any possible child operators.
        /// </summary>
        /// <param name="op">The operator to visit.</param>
        /// <returns>The coalesced operator.</returns>
        protected internal override QueryOperator VisitFirst(FirstOperator op)
        {
            var source = VisitAndConvert <MonadMember>(op.Source);

            if (source.QueryNodeType == QueryNodeType.Operator)
            {
                var sourceOp = (QueryOperator)source;
                if (sourceOp.NodeType == OperatorType.Where)
                {
                    var where = (WhereOperator)sourceOp;
                    if (op.ElementType == where.ElementType) // new C[0].Where<B>(_ => B.b).First<A>() can't be optimized
                    {
                        return(op.QueryExpressionFactory.First(
                                   op.ElementType,
                                   where.Source,
                                   where.Predicate));
                    }
                }
            }

            return(op.Update(source));
        }
Exemple #2
0
 /// <summary>
 /// Makes a <see cref="FirstOperator" /> with the given children.
 /// </summary>
 /// <param name="node">Original query expression.</param>
 /// <param name="source">Source query expression.</param>
 /// <returns>Representation of the original query expression.</returns>
 protected sealed override QueryOperator MakeFirst(FirstOperator node, MonadMember source)
 {
     return(node.QueryExpressionFactory.First(node.ElementType, source));
 }
Exemple #3
0
 /// <summary>
 /// Creates a textual representation of the FirstOperator with the given children.
 /// </summary>
 /// <param name="node">Original query expression.</param>
 /// <param name="source">Source query expression.</param>
 /// <returns>Representation of the original query expression.</returns>
 protected override string MakeFirst(FirstOperator node, string source)
 {
     return(string.Format(CultureInfo.InvariantCulture, "@First({0})", source));
 }
Exemple #4
0
 /// <summary>
 /// Makes a <see cref="FirstOperator" /> with the given children.
 /// </summary>
 /// <param name="node">Original query expression.</param>
 /// <param name="elementType">Element type for the resulting operator.</param>
 /// <param name="source">Source query expression.</param>
 /// <returns>Representation of the original query expression.</returns>
 protected virtual QueryOperator MakeFirst(FirstOperator node, Type elementType, MonadMember source)
 {
     return(node.QueryExpressionFactory.First(elementType, source));
 }