1 条件判断是否要加过滤条件
public static IQueryable<T> WhereIf<T>(
this IQueryable<T> source,
Expression<Func<T, bool>> predicate,
bool condition)
{
source.CheckNotNull<IQueryable<T>>(nameof (source));
predicate.CheckNotNull<Expression<Func<T, bool>>>(nameof (predicate));
return condition ? source.Where<T>(predicate) : source;
}
原文:https://www.cnblogs.com/xiewenyu/p/10688708.html