/// <summary> /// 分页查询| /// Executes a query, returning the paging data typed as T. /// </summary> /// <param name="pageNum">页码|page number</param> /// <param name="pageSize">页大小|page size</param> /// <param name="whereString">parameterized sql of "where",(example:whereString:name like @name)</param> /// <param name="param">whereString's param,(example:new { name = "google%" })</param> /// <param name="order">order param,(example:order:"createTime")</param> /// <param name="asc">Is ascending</param> /// <returns>返回分页数据|returning the paging data typed as T</returns> public IPage <T> QueryList(int pageNum, int pageSize, string whereString = null, object param = null, string order = null, bool asc = false) { IPage <T> paging = new Paging <T>(pageNum, pageSize); ISqlAdapter adapter = ConnectionBuilder.GetAdapter(this.DBConnection); var sqlbuilder = adapter.GetPageList(this, pageNum, pageSize, whereString, param, order, asc); paging.data = DBConnection.Query <T>(sqlbuilder.SQL, sqlbuilder.Arguments).ToList(); paging.dataCount = QueryCount(whereString, param); return(paging); }
/// <summary> /// 查询列表| /// Executes a query, returning the data typed as T. /// </summary> /// <param name="whereString">whereString,(example:whereString:name like @name)</param> /// <param name="param">whereString's param,(example:new { name = "google%" })</param> /// <param name="order">order param,(example:order:"createTime")</param> /// <param name="asc">Is ascending</param> /// <returns>returning the data list typed as T.</returns> public async Task <IEnumerable <T> > QueryListAsync(string whereString = null, object param = null, string order = null, bool asc = false) { if (string.IsNullOrEmpty(whereString) && string.IsNullOrEmpty(order)) { return(await DBConnection.GetAllAsync <T>()); } else { ISqlAdapter adapter = ConnectionBuilder.GetAdapter(this.DBConnection); var sqlbuilder = adapter.GetPageList(this, whereString: whereString, param: param, order: order, asc: asc); return(await DBConnection.QueryAsync <T>(sqlbuilder.SQL, sqlbuilder.Arguments)); } }
/// <summary> /// 分页查询| /// Executes a query, returning the paging data typed as T. /// </summary> /// <param name="tableNameFormat">Table Name Format placeholder</param> /// <param name="pageNum">页码|page number</param> /// <param name="pageSize">页大小|page size</param> /// <param name="whereString">parameterized sql of "where",(example:whereString:name like @name)</param> /// <param name="param">whereString's param,(example:new { name = "google%" })</param> /// <param name="order">order param,(example:order:"createTime")</param> /// <param name="asc">Is ascending</param> /// <returns>返回分页数据|returning the paging data typed as T</returns> public async Task <IPage <T> > QueryListAsync(string tableNameFormat, int pageNum, int pageSize, string whereString = null, object param = null, string order = null, bool asc = false) { IPage <T> paging = new Paging <T>(pageNum, pageSize); ISqlAdapter adapter = ConnectionBuilder.GetAdapter(this.DBConnection); var sqlbuilder = adapter.GetPageList(tableNameFormat, this, pageNum, pageSize, whereString, param, order, asc); var data = await DBConnection.QueryAsync <T>(sqlbuilder.ESQL, sqlbuilder.Arguments, transaction : _dbTransaction); var dataCount = await QueryCountAsync(whereString, param); paging.data = data.ToList(); paging.dataCount = dataCount; return(paging); }
/// <summary> /// 查询列表| /// Executes a query, returning the data typed as T. /// </summary> /// <param name="whereString">whereString,(example:whereString:name like @name)</param> /// <param name="param">whereString's param,(example:new { name = "google%" })</param> /// <param name="order">order param,(example:order:"createTime")</param> /// <param name="asc">Is ascending</param> /// <returns>returning the data list typed as T.</returns> public List <T> QueryList(string whereString = null, object param = null, string order = null, bool asc = false) { if (string.IsNullOrEmpty(whereString) && string.IsNullOrEmpty(order)) { return(DBConnection.GetAll <T>().ToList()); } else { ISqlAdapter adapter = ConnectionBuilder.GetAdapter(this.DBConnection); var sqlbuilder = adapter.GetPageList(this, whereString: whereString, param: param, order: order, asc: asc); return(DBConnection.Query <T>(sqlbuilder.SQL, sqlbuilder.Arguments).ToList()); } }
/// <summary> /// 工作单元基类| /// Base UnitOfWork /// </summary> public UnitOfWork(string dbAliase = "") { this.context = ConnectionBuilder.CreateConnection(dbAliase); this.context.Open(); this.transaction = this.context.BeginTransaction(); }