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