/// <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) { 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); }
/// <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); }
/// <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<TSource> 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); }
/// <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; }
/// <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.Table.CreateQuery <TSource>(Expression.Call( null, CqlMthHelps.WhereMi, new[] { source.Expression, predicate })); source.CopyQueryPropertiesTo(ret); return(ret); }
/// <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); }
/// <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.Table.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.Table.CreateQuery <TSource>(Expression.Call( null, CqlMthHelps.AllowFilteringMi, new[] { source.Expression })); source.CopyQueryPropertiesTo(ret); return(ret); }
/// <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 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 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); }
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); }
/// <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); }
internal CqlQuerySingleElement(Expression expression, CqlQuery <TEntity> source) : base(expression, source.Table, source.MapperFactory, source.StatementFactory, source.PocoData) { }