1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using System;
- using System.Linq;
- using System.Linq.Expressions;
- namespace Ips.Library.Basic
- {
- public static class QueryableExtensions
- {
- public static IQueryable<T> PageBy<T>(this IQueryable<T> query, int skipCount, int maxResultCount)
- {
- return query.Skip(skipCount).Take(maxResultCount);
- }
- public static TQueryable PageBy<T, TQueryable>(this TQueryable query, int skipCount, int maxResultCount)
- where TQueryable : IQueryable<T>
- {
- return (TQueryable)query.Skip(skipCount).Take(maxResultCount);
- }
- public static IQueryable<T> WhereIf<T>(this IQueryable<T> query, bool condition, Expression<Func<T, bool>> predicate)
- {
- return condition
- ? query.Where(predicate)
- : query;
- }
- public static TQueryable WhereIf<T, TQueryable>(this TQueryable query, bool condition, Expression<Func<T, bool>> predicate)
- where TQueryable : IQueryable<T>
- {
- return condition
- ? (TQueryable)query.Where(predicate)
- : query;
- }
- public static IQueryable<T> WhereIf<T>(this IQueryable<T> query, bool condition, Expression<Func<T, int, bool>> predicate)
- {
- return condition
- ? query.Where(predicate)
- : query;
- }
- public static TQueryable WhereIf<T, TQueryable>(this TQueryable query, bool condition, Expression<Func<T, int, bool>> predicate)
- where TQueryable : IQueryable<T>
- {
- return condition
- ? (TQueryable)query.Where(predicate)
- : query;
- }
- }
- }
|