Queryable查询扩展

        /// <summary>
    /// 查询扩展
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public static  class QueryableExtensions
    {
        /// <summary>
        /// Linq If 条件判断语句 IfWhere(条件,p=>xxx)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">IQueryable 源数据</param>
        /// <param name="condition">判断条件</param>
        /// <param name="predicate">条件表达式</param>
        /// <returns>返回加了条件的 IQueryable数据源</returns>
        public static IQueryable<T> IfWhere<T>(this IQueryable<T> source,bool condition, Expression<Func<T, bool>> predicate)
        {
            return condition ? source.Where(predicate) : source;
        }
        /// <summary>
        /// Linq If 条件判断语句 IfWhere(条件,p=>xxx)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">IEnumerable 源数据</param>
        /// <param name="condition">判断条件</param>
        /// <param name="predicate">条件表达式</param>
        /// <returns>返回加了条件的 IEnumerable数据源</returns>
        public static IEnumerable<T> IfWhere<T>(this IEnumerable<T> source, bool condition, Func<T, bool> predicate)
        {
            return condition ? source.Where(predicate) : source;
        }
        }

 

posted @ 2019-06-10 11:02 _York 阅读(...) 评论(...) 编辑 收藏