using System.Linq.Expressions; namespace Edge.Core.Core.database { public static class QueryableExtensions { /// /// 根据条件动态地应用 WHERE 子句。 /// /// 实体类型。 /// 原始的 IQueryable 查询。 /// 是否应用 WHERE 子句的条件。 /// 要应用的 WHERE 子句的条件表达式。 /// 根据条件返回应用了 WHERE 子句或未应用的 IQueryable 查询。 public static IQueryable WhereIf(this IQueryable query, bool condition, Expression> predicate) { return condition ? query.Where(predicate) : query; } } }