Added alternative WhereIf and PageIf for extended queryables.

pull/272/head
Halil İbrahim Kalkan 7 years ago
parent cbc2eebb2a
commit 1087199237

@ -19,6 +19,17 @@ namespace System.Linq
return query.Skip(skipCount).Take(maxResultCount);
}
/// <summary>
/// Used for paging. Can be used as an alternative to Skip(...).Take(...) chaining.
/// </summary>
public static TQueryable PageBy<T, TQueryable>([NotNull] this TQueryable query, int skipCount, int maxResultCount)
where TQueryable : IQueryable<T>
{
Check.NotNull(query, nameof(query));
return (TQueryable) query.Skip(skipCount).Take(maxResultCount);
}
/// <summary>
/// Filters a <see cref="IQueryable{T}"/> by given predicate if given condition is true.
/// </summary>
@ -35,6 +46,23 @@ namespace System.Linq
: query;
}
/// <summary>
/// Filters a <see cref="IQueryable{T}"/> by given predicate if given condition is true.
/// </summary>
/// <param name="query">Queryable to apply filtering</param>
/// <param name="condition">A boolean value</param>
/// <param name="predicate">Predicate to filter the query</param>
/// <returns>Filtered or not filtered query based on <paramref name="condition"/></returns>
public static TQueryable WhereIf<T, TQueryable>([NotNull] this TQueryable query, bool condition, Expression<Func<T, bool>> predicate)
where TQueryable : IQueryable<T>
{
Check.NotNull(query, nameof(query));
return condition
? (TQueryable) query.Where(predicate)
: query;
}
/// <summary>
/// Filters a <see cref="IQueryable{T}"/> by given predicate if given condition is true.
/// </summary>
@ -50,5 +78,22 @@ namespace System.Linq
? query.Where(predicate)
: query;
}
/// <summary>
/// Filters a <see cref="IQueryable{T}"/> by given predicate if given condition is true.
/// </summary>
/// <param name="query">Queryable to apply filtering</param>
/// <param name="condition">A boolean value</param>
/// <param name="predicate">Predicate to filter the query</param>
/// <returns>Filtered or not filtered query based on <paramref name="condition"/></returns>
public static TQueryable WhereIf<T, TQueryable>([NotNull] this TQueryable query, bool condition, Expression<Func<T, int, bool>> predicate)
where TQueryable : IQueryable<T>
{
Check.NotNull(query, nameof(query));
return condition
? (TQueryable) query.Where(predicate)
: query;
}
}
}

Loading…
Cancel
Save