QueryableExtensions.cs 852 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. namespace YLShipBuildLandMap.Entity.ViewModel
  7. {
  8. public static class QueryableExtensions
  9. {
  10. public static IQueryable<T> WhereIf<T>(this IQueryable<T> query, bool condition, Expression<Func<T, bool>> predicate)
  11. {
  12. return condition ? query.Where(predicate) : query;
  13. }
  14. public static IQueryable<T> WhereIf<T>(this IQueryable<T> query, bool condition, Expression<Func<T, int, bool>> predicate)
  15. {
  16. return condition ? query.Where(predicate) : query;
  17. }
  18. public static IEnumerable<T> WhereIf<T>(this IEnumerable<T> query, bool condition, Func<T, bool> predicate)
  19. {
  20. return condition ? query.Where(predicate) : query;
  21. }
  22. }
  23. }