コード例 #1
0
        /// <summary>
        /// Returns the number of rows matching the query.
        /// To execute this CqlScalar use <c>Execute()</c> method.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <param name="source">The CqlQuery&lt;TSource&gt; to return the first element of.</param>
        /// <returns>A single result: the number of rows matching the query.</returns>
        public static CqlScalar <long> Count <TSource>(this CqlQuery <TSource> source)
        {
            var ret = new CqlScalar <long>(source.Expression, source.Provider);

            source.CopyQueryPropertiesTo(ret);
            return(ret);
        }
コード例 #2
0
        /// <summary>
        /// Returns a representation of a UPDATE cql statement
        /// </summary>
        public static CqlUpdate Update <TSource>(this CqlQuery <TSource> source)
        {
            var ret = new CqlUpdate(source.Expression, source.Table, source.StatementFactory, source.PocoData, source.MapperFactory);

            source.CopyQueryPropertiesTo(ret);
            return(ret);
        }
コード例 #3
0
        public static CqlUpdate Update <TSource>(this CqlQuery <TSource> source)
        {
            var ret = new CqlUpdate(source.Expression, source.Provider);

            source.CopyQueryPropertiesTo(ret);
            return(ret);
        }
コード例 #4
0
        /// <summary>
        /// Projects each element of a sequence into a new form.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <typeparam name="TResult">The type of the value returned by selector.</typeparam>
        /// <param name="source">A CqlQuery&lt;TSource&gt; which after execution returns a sequence of values to invoke a transform function on.</param>
        /// <param name="selector">A transform function to apply to each element.</param>
        /// <returns>a CqlQuery&lt;TSource&gt; which after execution will return an IEnumerable&lt;TSource&gt; whose elements
        /// are the result of invoking the transform function on each element of source.
        /// To execute this CqlQuery use <c>Execute()</c> method.</returns>
        public static CqlQuery <TResult> Select <TSource, TResult>(this CqlQuery <TSource> source, Expression <Func <TSource, TResult> > selector)
        {
            Expression         expression = source.Expression;
            CqlQuery <TResult> result;

            if (typeof(TSource) != typeof(TResult))
            {
                //Its a client projection of an existent CqlQuery
                if (!(source is IClientProjectionCqlQuery))
                {
                    //The SELECT expression changed
                    expression = Expression.Call(null, CqlMthHelps.SelectMi, new[] { source.Expression, selector });
                    result     = new ClientProjectionCqlQuery <TSource, TResult>(expression, source, selector, true);
                }
                else
                {
                    //its a client projection of a client projection
                    //we should use the original source.Expression
                    result = new ClientProjectionCqlQuery <TSource, TResult>(expression, source, selector, true);
                }
            }
            else
            {
                expression = Expression.Call(null, CqlMthHelps.SelectMi, new[] { source.Expression, selector });
                //Its a mapper based projection
                result = (CqlQuery <TResult>)source.Table.CreateQuery <TResult>(expression);
            }
            source.CopyQueryPropertiesTo(result);
            return(result);
        }
コード例 #5
0
        /// <summary>
        /// Returns the number of rows matching the query.
        /// To execute this CqlScalar use <c>Execute()</c> method.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <param name="source">The CqlQuery&lt;TSource&gt; to return the first element of.</param>
        /// <returns>A single result: the number of rows matching the query.</returns>
        public static CqlScalar <long> Count <TSource>(this CqlQuery <TSource> source)
        {
            var ret = new CqlScalar <long>(source.Expression, source.Table, source.StatementFactory, source.PocoData);

            source.CopyQueryPropertiesTo(ret);
            return(ret);
        }
コード例 #6
0
 /// <summary>
 /// Creates a new instance of <see cref="ClientProjectionCqlQuery{TSource, TResult}"/>.
 /// </summary>
 /// <param name="expression">The complete query expression</param>
 /// <param name="source">The source <see cref="CqlQuery{TSource}"/></param>
 /// <param name="projectionExpression">The projection expression</param>
 /// <param name="canCompile">Determines if the projection can be compiled and the delegate called.</param>
 internal ClientProjectionCqlQuery(Expression expression, CqlQuery <TSource> source,
                                   Expression <Func <TSource, TResult> > projectionExpression, bool canCompile) :
     base(expression, source.Table, source.MapperFactory, source.StatementFactory, source.PocoData)
 {
     _source = source;
     _projectionExpression = projectionExpression;
     _canCompile           = canCompile;
 }
コード例 #7
0
        /// <summary>
        /// Returns a representation of a UPDATE ... IF EXISTS cql statement, for Lightweight Transactions support.
        /// </summary>
        public static CqlConditionalCommand <TSource> UpdateIfExists <TSource>(this CqlQuery <TSource> source)
        {
            var update = new CqlUpdate(Expression.Call(null, CqlMthHelps.UpdateIfExistsMi, source.Expression),
                                       source.Table, source.StatementFactory, source.PocoData, source.MapperFactory);

            source.CopyQueryPropertiesTo(update);
            return(new CqlConditionalCommand <TSource>(update, source.MapperFactory));
        }
コード例 #8
0
        /// <summary>
        /// Projects each element of a sequence into a new form.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <typeparam name="TResult">The type of the value returned by selector.</typeparam>
        /// <param name="source">A CqlQuery&lt;TSource&gt; which after execution returns a sequence of values to invoke a transform function on.</param>
        /// <param name="selector">A transform function to apply to each element.</param>
        /// <returns>a CqlQuery&lt;TSource&gt; which after execution will return an IEnumerable&lt;TSource&gt; whose elements
        /// are the result of invoking the transform function on each element of source.
        /// To execute this CqlQuery use <c>Execute()</c> method.</returns>
        public static CqlQuery <TResult> Select <TSource, TResult>(this CqlQuery <TSource> source, Expression <Func <TSource, TResult> > selector)
        {
            var ret = (CqlQuery <TResult>)source.Table.CreateQuery <TResult>(Expression.Call(
                                                                                 null, CqlMthHelps.SelectMi,
                                                                                 new[] { source.Expression, selector }));

            source.CopyQueryPropertiesTo(ret);
            return(ret);
        }
コード例 #9
0
        /// <summary>
        /// The ALLOW FILTERING option allows to explicitly allow queries that require filtering.
        /// Please note that a query using ALLOW FILTERING may thus have unpredictable performance (for the definition above), i.e. even a query that selects a handful of records may exhibit performance that depends on the total amount of data stored in the cluster.
        /// </summary>
        public static CqlQuery <TSource> AllowFiltering <TSource>(this CqlQuery <TSource> source)
        {
            var ret = (CqlQuery <TSource>)source.Table.CreateQuery <TSource>(Expression.Call(
                                                                                 null, CqlMthHelps.AllowFilteringMi,
                                                                                 new[] { source.Expression }));

            source.CopyQueryPropertiesTo(ret);
            return(ret);
        }
コード例 #10
0
        /// <summary>
        /// Sorts the elements, which are returned from CqlQuery, in ascending order according to a key.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <typeparam name="TKey">The type of the key returned by keySelector.</typeparam>
        /// <param name="source">A sequence of values to order, returned from CqlQuery&lt;TSource&gt;.</param>
        /// <param name="keySelector">A function to extract a key from an element.</param>
        /// <returns>a CqlQuery&lt;TSource&gt; which after execution returns an IEnumerable&lt;TSource&gt; sorted in ascending manner according to a key.</returns>
        public static CqlQuery <TSource> OrderBy <TSource, TKey>(this CqlQuery <TSource> source, Expression <Func <TSource, TKey> > keySelector)
        {
            var ret = (CqlQuery <TSource>)source.Table.CreateQuery <TSource>(Expression.Call(
                                                                                 null, CqlMthHelps.OrderByMi,
                                                                                 new[] { source.Expression, keySelector }));

            source.CopyQueryPropertiesTo(ret);
            return(ret);
        }
コード例 #11
0
        /// <summary>
        /// Returns a representation of a UPDATE ... IF ... cql statement, for Lightweight Transactions support
        /// </summary>
        public static CqlConditionalCommand <TSource> UpdateIf <TSource>(this CqlQuery <TSource> source, Expression <Func <TSource, bool> > predicate)
        {
            var update = new CqlUpdate(Expression.Call(
                                           null, CqlMthHelps.UpdateIfMi,
                                           new[] { source.Expression, predicate }), source.Table, source.StatementFactory, source.PocoData);

            source.CopyQueryPropertiesTo(update);
            return(new CqlConditionalCommand <TSource>(update, source.MapperFactory));
        }
コード例 #12
0
        /// <summary>
        /// Returns a CqlQuery which after execution will return IEnumerable&lt;TSource&gt;
        /// with specified number of contiguous elements from the start of a sequence.
        /// To execute this CqlQuery use <c>Execute()</c> method.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <param name="source">The CqlQuery&lt;TSource&gt; to return the first element of.</param>
        /// <param name="count">The number of elements to return.</param>
        /// <returns>a CqlQuery&lt;TSource&gt; which after execution will return IEnumerable&lt;TSource&gt;
        /// with specified number of contiguous elements from the start of a sequence.</returns>
        public static CqlQuery <TSource> Take <TSource>(this CqlQuery <TSource> source, int count)
        {
            var ret = (CqlQuery <TSource>)source.Table.CreateQuery <TSource>(Expression.Call(
                                                                                 null, CqlMthHelps.TakeMi,
                                                                                 new[] { source.Expression, Expression.Constant(count) }));

            source.CopyQueryPropertiesTo(ret);
            return(ret);
        }
コード例 #13
0
        /// <summary>
        ///  Returns a CqlQuery which after execution returns filtered sequence of values based on a predicate.
        ///  To execute this CqlQuery use <c>Execute()</c> method.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <param name="source">The CqlQuery&lt;TSource&gt; to filter.</param>
        /// <param name="predicate">A function to test each element for a condition.</param>
        /// <returns>a CqlQuery&lt;TSource&gt; which after execution will return an IEnumerable&lt;TSource&gt;
        /// that contains elements from the input sequence that satisfy the condition.</returns>
        public static CqlQuery <TSource> Where <TSource>(this CqlQuery <TSource> source, Expression <Func <TSource, bool> > predicate)
        {
            var ret = (CqlQuery <TSource>)source.Table.CreateQuery <TSource>(Expression.Call(
                                                                                 null, CqlMthHelps.WhereMi,
                                                                                 new[] { source.Expression, predicate }));

            source.CopyQueryPropertiesTo(ret);
            return(ret);
        }
コード例 #14
0
        /// <summary>
        /// Returns a CqlQuery which after execution will return the first element of a sequence,
        /// or a default value if the sequence contains no elements.
        /// To execute this CqlQuery use <c>Execute()</c> method.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <param name="source">The CqlQuery&lt;TSource&gt; to return the first element of.</param>
        /// <returns><c>a CqlQuery&lt;TSource&gt; which after execution will return default(TSource)</c> if source is empty,
        /// otherwise the first element in source.</returns>
        public static CqlQuerySingleElement <TSource> FirstOrDefault <TSource>(this CqlQuery <TSource> source)
        {
            var ret = new CqlQuerySingleElement <TSource>(source.Table.CreateQuery <TSource>(Expression.Call(
                                                                                                 null, CqlMthHelps.FirstOrDefaultMi,
                                                                                                 new[] { source.Expression, Expression.Constant(1) })).Expression, source);

            source.CopyQueryPropertiesTo(ret);
            return(ret);
        }
コード例 #15
0
        public static CqlUpdate UpdateIf <TSource>(this CqlQuery <TSource> source, Expression <Func <TSource, bool> > predicate)
        {
            var ret = new CqlUpdate(Expression.Call(
                                        null, CqlMthHelps.UpdateIfMi,
                                        new[] { source.Expression, predicate }), source.Provider);

            source.CopyQueryPropertiesTo(ret);
            return(ret);
        }
コード例 #16
0
        /// <summary>
        /// Sorts the elements, which are returned from CqlQuery, in descending order according to a key.
        /// </summary>
        public static CqlQuery <TSource> ThenByDescending <TSource, TKey>(this CqlQuery <TSource> source, Expression <Func <TSource, TKey> > func)
        {
            var ret = (CqlQuery <TSource>)source.Table.CreateQuery <TSource>(Expression.Call(
                                                                                 null, CqlMthHelps.ThenByDescendingMi,
                                                                                 new[] { source.Expression, func }));

            source.CopyQueryPropertiesTo(ret);
            return(ret);
        }
コード例 #17
0
        public static CqlQuery <TResult> Select <TGroup, TSource, TResult>(
            this CqlQuery <IGrouping <TGroup, TSource> > source,
            Expression <Func <IGrouping <TGroup, TSource>, TResult> > selector)
        {
            var expression = Expression.Call(null, CqlMthHelps.SelectMi, new[] { source.Expression, selector });
            var result     = new ClientProjectionCqlQuery <IGrouping <TGroup, TSource>, TResult>(
                expression, source, selector, false);

            result.CopyQueryPropertiesTo(result);
            return(result);
        }
コード例 #18
0
        /// <summary>
        ///  Returns a CqlQuery which after execution returns grouped sequence of values based on a predicate.
        ///  To execute this CqlQuery use <c>Execute()</c> method.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <typeparam name="TKey">The type of the value returned by selector.</typeparam>
        /// <param name="source">The CqlQuery&lt;TSource&gt; to filter.</param>
        /// <param name="predicate">A function to test each element for a condition.</param>
        /// <returns>a CqlQuery&lt;TSource&gt; which after execution will return an IEnumerable&lt;TSource&gt;
        /// that contains elements from the input sequence that satisfy the condition.</returns>
        public static CqlQuery <IGrouping <TKey, TSource> > GroupBy <TKey, TSource>(this CqlQuery <TSource> source,
                                                                                    Expression <Func <TSource, TKey> > predicate)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (predicate == null)
            {
                throw new ArgumentNullException("predicate");
            }
            var result = (CqlQuery <IGrouping <TKey, TSource> >)source.Table.CreateQuery <IGrouping <TKey, TSource> >(Expression.Call(
                                                                                                                          null, CqlMthHelps.GroupByMi,
                                                                                                                          new[] { source.Expression, predicate }));

            source.CopyQueryPropertiesTo(result);
            return(result);
        }
コード例 #19
0
 internal CqlQuerySingleElement(Expression expression, CqlQuery <TEntity> source)
     : base(expression, source.Table, source.MapperFactory, source.StatementFactory, source.PocoData)
 {
 }
コード例 #20
0
 /// <summary>
 /// Returns a CqlQuery which after execution will return IEnumerable&lt;TSource&gt;
 /// with specified number of contiguous elements from the start of a sequence.
 /// To execute this CqlQuery use <code>Execute()</code> method.
 /// </summary>
 /// <typeparam name="TSource">The type of the elements of source.</typeparam>
 /// <param name="source">The CqlQuery&lt;TSource&gt; to return the first element of.</param>
 /// <param name="count">The number of elements to return.</param>
 /// <returns>a CqlQuery&lt;TSource&gt; which after execution will return IEnumerable&lt;TSource&gt;
 /// with specified number of contiguous elements from the start of a sequence.</returns>
 public static CqlQuery <TSource> Take <TSource>(this CqlQuery <TSource> source, int count)
 {
     return((CqlQuery <TSource>)source.Provider.CreateQuery <TSource>(Expression.Call(
                                                                          null, CqlMthHelps.TakeMi,
                                                                          new Expression[] { source.Expression, Expression.Constant(count) })));
 }
コード例 #21
0
 /// <summary>
 /// Returns a CqlQuery which after execution will return the first element of a sequence,
 /// or a default value if the sequence contains no elements.
 /// To execute this CqlQuery use <code>Execute()</code> method.
 /// </summary>
 /// <typeparam name="TSource">The type of the elements of source.</typeparam>
 /// <param name="source">The CqlQuery&lt;TSource&gt; to return the first element of.</param>
 /// <returns><code>a CqlQuery&lt;TSource&gt; which after execution will return default(TSource)</code> if source is empty,
 /// otherwise the first element in source.</returns>
 public static CqlQuerySingleElement <TSource> FirstOrDefault <TSource>(this CqlQuery <TSource> source)
 {
     return(new CqlQuerySingleElement <TSource>(source.Provider.CreateQuery <TSource>(Expression.Call(
                                                                                          null, CqlMthHelps.FirstOrDefaultMi,
                                                                                          new Expression[] { source.Expression, Expression.Constant(1) })).Expression, source.Provider));
 }
コード例 #22
0
 /// <summary>
 /// Sorts the elements, which are returned from CqlQuery, in ascending order according to a key.
 /// </summary>
 /// <typeparam name="TSource">The type of the elements of source.</typeparam>
 /// <typeparam name="TKey">The type of the key returned by keySelector.</typeparam>
 /// <param name="source">A sequence of values to order, returned from CqlQuery&lt;TSource&gt;.</param>
 /// <param name="keySelector">A function to extract a key from an element.</param>
 /// <returns>a CqlQuery&lt;TSource&gt; which after execution returns an IEnumerable&lt;TSource&gt; sorted in ascending manner according to a key.</returns>
 public static CqlQuery <TSource> OrderBy <TSource, TKey>(this CqlQuery <TSource> source, Expression <Func <TSource, TKey> > keySelector)
 {
     return((CqlQuery <TSource>)source.Provider.CreateQuery <TSource>(Expression.Call(
                                                                          null, CqlMthHelps.OrderByMi,
                                                                          new Expression[] { source.Expression, keySelector })));
 }
コード例 #23
0
 public static CqlQuery <TSource> ThenByDescending <TSource, TKey>(this CqlQuery <TSource> source, Expression <Func <TSource, TKey> > func)
 {
     return((CqlQuery <TSource>)source.Provider.CreateQuery <TSource>(Expression.Call(
                                                                          null, CqlMthHelps.ThenByDescendingMi,
                                                                          new Expression[] { source.Expression, func })));
 }
コード例 #24
0
 /// <summary>
 ///  Returns a CqlQuery which after execution returns filtered sequence of values based on a predicate.
 ///  To execute this CqlQuery use <code>Execute()</code> method.
 /// </summary>
 /// <typeparam name="TSource">The type of the elements of source.</typeparam>
 /// <param name="source">The CqlQuery&lt;TSource&gt; to filter.</param>
 /// <param name="predicate">A function to test each element for a condition.</param>
 /// <returns>a CqlQuery&lt;TSource&gt; which after execution will return an IEnumerable&lt;TSource&gt;
 /// that contains elements from the input sequence that satisfy the condition.</returns>
 public static CqlQuery <TSource> Where <TSource>(this CqlQuery <TSource> source, Expression <Func <TSource, bool> > predicate)
 {
     return((CqlQuery <TSource>)source.Provider.CreateQuery <TSource>(Expression.Call(
                                                                          null, CqlMthHelps.WhereMi,
                                                                          new Expression[] { source.Expression, predicate })));
 }
コード例 #25
0
 /// <summary>
 /// Returns a CqlScalar which after execution returns the number of elements in a sequence.
 /// To execute this CqlScalar use <code>Execute()</code> method.
 /// </summary>
 /// <typeparam name="TSource">The type of the elements of source.</typeparam>
 /// <param name="source">The CqlQuery&lt;TSource&gt; to return the first element of.</param>
 /// <returns>a CqlScalar&lt;long&gt; which after execution returns the number of elements in a sequence.</returns>
 public static CqlScalar <long> Count <TSource>(this CqlQuery <TSource> source)
 {
     return(new CqlScalar <long>(source.Expression, source.Provider));
 }
コード例 #26
0
 public static CqlUpdate Update <TSource>(this CqlQuery <TSource> source)
 {
     return(new CqlUpdate(source.Expression, source.Provider));
 }
コード例 #27
0
 /// <summary>
 /// Projects each element of a sequence into a new form.
 /// </summary>
 /// <typeparam name="TSource">The type of the elements of source.</typeparam>
 /// <typeparam name="TResult">The type of the value returned by selector.</typeparam>
 /// <param name="source">A CqlQuery&lt;TSource&gt; which after execution returns a sequence of values to invoke a transform function on.</param>
 /// <param name="selector">A transform function to apply to each element.</param>
 /// <returns>a CqlQuery&lt;TSource&gt; which after execution will return an IEnumerable&lt;TSource&gt; whose elements
 /// are the result of invoking the transform function on each element of source.
 /// To execute this CqlQuery use <code>Execute()</code> method.</returns>
 public static CqlQuery <TResult> Select <TSource, TResult>(this CqlQuery <TSource> source, Expression <Func <TSource, TResult> > selector)
 {
     return((CqlQuery <TResult>)source.Provider.CreateQuery <TResult>(Expression.Call(
                                                                          null, CqlMthHelps.SelectMi,
                                                                          new Expression[] { source.Expression, selector })));
 }