123456789101112131415161718192021222324252627 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- namespace YLShipBuildLandMap.Entity.ViewModel
- {
- public static class QueryableExtensions
- {
- 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 IQueryable<T> WhereIf<T>(this IQueryable<T> query, bool condition, Expression<Func<T, int, bool>> predicate)
- {
- return condition ? query.Where(predicate) : query;
- }
- public static IEnumerable<T> WhereIf<T>(this IEnumerable<T> query, bool condition, Func<T, bool> predicate)
- {
- return condition ? query.Where(predicate) : query;
- }
- }
- }
|