/// <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.MapperFactory); source.CopyQueryPropertiesTo(update); return(new CqlConditionalCommand <TSource>(update, source.MapperFactory)); }
/// <summary> /// Returns a CqlQuery which after execution will return IEnumerable<TSource> /// 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<TSource> to return the first element of.</param> /// <param name="count">The number of elements to return.</param> /// <returns>a CqlQuery<TSource> which after execution will return IEnumerable<TSource> /// 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); }
/// <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<TSource> to filter.</param> /// <param name="predicate">A function to test each element for a condition.</param> /// <returns>a CqlQuery<TSource> which after execution will return an IEnumerable<TSource> /// 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.Provider.CreateQuery <TSource>(Expression.Call( null, CqlMthHelps.WhereMi, new[] { source.Expression, predicate })); source.CopyQueryPropertiesTo(ret); return(ret); }
/// <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<TSource> to return the first element of.</param> /// <returns><c>a CqlQuery<TSource> 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); }
/// <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<TSource> 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<TSource> which after execution will return an IEnumerable<TSource> 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.Provider.CreateQuery <TResult>(Expression.Call( null, CqlMthHelps.SelectMi, new[] { source.Expression, selector })); source.CopyQueryPropertiesTo(ret); return(ret); }
public static CqlQuery <TSource> ThenByDescending <TSource, TKey>(this CqlQuery <TSource> source, Expression <Func <TSource, TKey> > func) { var ret = (CqlQuery <TSource>)source.Provider.CreateQuery <TSource>(Expression.Call( null, CqlMthHelps.ThenByDescendingMi, new[] { source.Expression, func })); source.CopyQueryPropertiesTo(ret); return(ret); }
/// <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<TSource>.</param> /// <param name="keySelector">A function to extract a key from an element.</param> /// <returns>a CqlQuery<TSource> which after execution returns an IEnumerable<TSource> 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.Provider.CreateQuery <TSource>(Expression.Call( null, CqlMthHelps.OrderByMi, new[] { source.Expression, keySelector })); source.CopyQueryPropertiesTo(ret); return(ret); }
/// <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.Provider.CreateQuery <TSource>(Expression.Call( null, CqlMthHelps.AllowFilteringMi, new[] { source.Expression })); source.CopyQueryPropertiesTo(ret); return(ret); }
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); }
/// <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<TSource> to filter.</param> /// <param name="predicate">A function to test each element for a condition.</param> /// <returns>a CqlQuery<TSource> which after execution will return an IEnumerable<TSource> /// 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); }