public TEntity FirstOrDefault(Expression <Func <TEntity, bool> > predicate = null) { if (predicate == null) { return(SlaveDb.Set <TEntity>().FirstOrDefault()); } return(SlaveDb.Set <TEntity>().FirstOrDefault(predicate)); }
public int Count(Expression <Func <TEntity, bool> > predicate = null) { var query = SlaveDb.Set <TEntity>().AsNoTracking(); return(predicate == null ? query.Count() : query.Count(predicate)); }
/// <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)); }
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()); }
/// <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(); }
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()); }
/// <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(); }
public TEntity FindById(object id) { return(SlaveDb.Set <TEntity>().Find(id)); }
/// <summary> /// 判断对象是否存在 /// </summary> /// <param name="whereLambd"></param> /// <returns></returns> public bool Any(Expression <Func <T, bool> > whereLambd) { return(SlaveDb.Set <T>().Where(whereLambd).Any()); }
/// <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()); }
/// <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)); }
/// <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(); }
public List <TEntity> FindAll(string order = null) { return(order == null?SlaveDb.Set <TEntity>().ToList() : SlaveDb.Set <TEntity>().OrderBy(order).ToList()); }
/// <summary> /// 根据主键查询 /// </summary> /// <param name="id"></param> /// <returns></returns> public T FindById(dynamic id) { return(SlaveDb.Set <T>().Find(id)); }
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()); }
public IQueryable <TEntity> Find(Expression <Func <TEntity, bool> > predicate = null) { return(predicate == null ? SlaveDb.Set <TEntity>() : SlaveDb.Set <TEntity>().Where(predicate)); }
public bool Exists(Expression <Func <TEntity, bool> > predicate) { return(SlaveDb.Set <TEntity>().Any(predicate)); }