Пример #1
0
 public TEntity FirstOrDefault(Expression <Func <TEntity, bool> > predicate = null)
 {
     if (predicate == null)
     {
         return(SlaveDb.Set <TEntity>().FirstOrDefault());
     }
     return(SlaveDb.Set <TEntity>().FirstOrDefault(predicate));
 }
Пример #2
0
        public int Count(Expression <Func <TEntity, bool> > predicate = null)
        {
            var query = SlaveDb.Set <TEntity>().AsNoTracking();

            return(predicate == null
                ? query.Count()
                : query.Count(predicate));
        }
Пример #3
0
 /// <summary>
 /// 获取默认一条数据,没有则为NULL
 /// </summary>
 /// <param name="whereLambda"></param>
 /// <returns></returns>
 public T FirstOrDefault(Expression <Func <T, bool> > whereLambda = null)
 {
     if (whereLambda == null)
     {
         return(SlaveDb.Set <T>().FirstOrDefault());
     }
     return(SlaveDb.Set <T>().FirstOrDefault(whereLambda));
 }
Пример #4
0
        public List <TEntity> Page(int page, int pageSize, out int total, string order, Expression <Func <TEntity, bool> > predicate = null)
        {
            // 分页 一定注意: Skip 之前一定要 OrderBy
            IQueryable <TEntity> query = SlaveDb.Set <TEntity>().OrderBy(order);

            if (predicate != null)
            {
                query = query.Where(predicate);
            }
            total = query.Count();
            return(query.PageBy((page - 1) * pageSize, pageSize).ToList());
        }
Пример #5
0
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="rows">总条数</param>
        /// <param name="ordering">排序条件(一定要有)</param>
        /// <param name="whereLambda">查询添加(可有,可无)</param>
        /// <returns></returns>
        public List <T> Page(int pageIndex, int pageSize, out int rows, string ordering, Expression <Func <T, bool> > whereLambda = null)
        {
            // 分页 一定注意: Skip 之前一定要 OrderBy
            var data = SlaveDb.Set <T>();//.OrderBy(ordering);

            if (whereLambda != null)
            {
                // data = data.Where(whereLambda);
            }
            rows = data.Count();
            return(null);//data.PageBy((pageIndex - 1) * pageSize, pageSize).ToList();
        }
Пример #6
0
        public List <TEntity> Page(int page, int pageSize, out int total, Expression <Func <TEntity, TKey> > orderBy, Expression <Func <TEntity, bool> > predicate = null, bool desc = true)
        {
            IQueryable <TEntity> query = desc
                ? SlaveDb.Set <TEntity>().OrderByDescending(orderBy)
                : SlaveDb.Set <TEntity>().OrderBy(orderBy);

            if (predicate != null)
            {
                query = query.Where(predicate);
            }
            total = query.Count();
            return(query.PageBy((page - 1) * pageSize, pageSize).ToList());
        }
Пример #7
0
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="rows">总条数</param>
        /// <param name="orderBy">排序条件(一定要有)</param>
        /// <param name="whereLambda">查询添加(可有,可无)</param>
        /// <param name="isOrder">是否是Order排序</param>
        /// <returns></returns>
        public List <T> Page <TKey>(int pageIndex, int pageSize, out int rows, Expression <Func <T, TKey> > orderBy, Expression <Func <T, bool> > whereLambda = null, bool isOrder = true)
        {
            IQueryable <T> data = isOrder ?
                                  SlaveDb.Set <T>().OrderBy(orderBy) :
                                  SlaveDb.Set <T>().OrderByDescending(orderBy);

            if (whereLambda != null)
            {
                data = data.Where(whereLambda);
            }
            rows = data.Count();
            return(null);// data.PageBy((pageIndex - 1) * pageSize, pageSize).ToList();
        }
Пример #8
0
 public TEntity FindById(object id)
 {
     return(SlaveDb.Set <TEntity>().Find(id));
 }
Пример #9
0
 /// <summary>
 /// 判断对象是否存在
 /// </summary>
 /// <param name="whereLambd"></param>
 /// <returns></returns>
 public bool Any(Expression <Func <T, bool> > whereLambd)
 {
     return(SlaveDb.Set <T>().Where(whereLambd).Any());
 }
Пример #10
0
 /// <summary>
 /// 获取数量
 /// </summary>
 /// <param name="whereLambd"></param>
 /// <returns></returns>
 public int GetCount(Expression <Func <T, bool> > whereLambd = null)
 {
     return(whereLambd == null?SlaveDb.Set <T>().Count()
                : SlaveDb.Set <T>().Where(whereLambd).Count());
 }
Пример #11
0
 /// <summary>
 /// 带条件查询获取数据
 /// </summary>
 /// <param name="whereLambda"></param>
 /// <returns></returns>
 public IQueryable <T> GetAllIQueryable(Expression <Func <T, bool> > whereLambda = null)
 {
     return(whereLambda == null?SlaveDb.Set <T>() : SlaveDb.Set <T>().Where(whereLambda));
 }
Пример #12
0
        /// <summary>
        /// 带条件查询获取数据
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <param name="ordering"></param>
        /// <returns></returns>
        public List <T> GetAll(Expression <Func <T, bool> > whereLambda, string ordering = null)
        {
            var iQueryable = SlaveDb.Set <T>().Where(whereLambda);

            return(null);// ordering == null? iQueryable.ToList(): iQueryable.OrderBy(ordering).ToList();
        }
Пример #13
0
 public List <TEntity> FindAll(string order = null)
 {
     return(order == null?SlaveDb.Set <TEntity>().ToList() : SlaveDb.Set <TEntity>().OrderBy(order).ToList());
 }
Пример #14
0
 /// <summary>
 /// 根据主键查询
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public T FindById(dynamic id)
 {
     return(SlaveDb.Set <T>().Find(id));
 }
Пример #15
0
        public List <TEntity> FindList(Expression <Func <TEntity, bool> > predicate, string order = null)
        {
            var query = SlaveDb.Set <TEntity>().Where(predicate);

            return(order == null?query.ToList() : query.OrderBy(order).ToList());
        }
Пример #16
0
 public IQueryable <TEntity> Find(Expression <Func <TEntity, bool> > predicate = null)
 {
     return(predicate == null
         ? SlaveDb.Set <TEntity>()
         : SlaveDb.Set <TEntity>().Where(predicate));
 }
Пример #17
0
 public bool Exists(Expression <Func <TEntity, bool> > predicate)
 {
     return(SlaveDb.Set <TEntity>().Any(predicate));
 }