/// <summary> /// Get PagedResultSet from a execute query with not nested object with/without TotalCount using the IncludeMetada /// </summary> /// <param name="fullSqlQuery">Sql Query to execute</param> /// <param name="filter">The SearchFilter </param> /// <param name="param">Parameters to blind with the sql query</param> /// <param name="buffered"></param> /// <returns></returns> public IPaginatedList <TReturn> ExecutePagedQuery <T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>(Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn> func, string fullSqlQuery, ISearchFilter filter, object param = null, string splitOn = "id", bool buffered = true) { // Paging construct helper string sqlGetQuery = PagedQueryBuilder.PagedQuery(fullSqlQuery, filter, ref param); SqlMapper.GridReader reader = DbConnection.QueryMultiple(sqlGetQuery, param, CurrentTransaction); Type[] types = { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9) }; IList <TReturn> entity = (IList <TReturn>)reader.Read(types, objects => func((T1)objects[0], (T2)objects[1], (T3)objects[2], (T4)objects[3], (T5)objects[4], (T6)objects[5], (T7)objects[6], (T8)objects[7], (T9)objects[8]), splitOn, buffered); int?totalCount = filter.IncludeMetadata ? reader.ReadSingleOrDefault <int?>() : null; return(new PaginatedList <TReturn>(entity, filter, totalCount)); }
/// <summary> /// Get PagedResultSet from a execute query with not nested object with/without TotalCount using the IncludeMetada /// </summary> /// <param name="fullSqlQuery">Sql Query to execute</param> /// <param name="filter">The SearchFilter </param> /// <param name="param">Parameters to blind with the sql query</param> /// <param name="buffered"></param> /// <returns></returns> public IPaginatedList <TReturn> ExecutePagedQuery <TReturn>(string fullSqlQuery, ISearchFilter filter, object param = null, bool buffered = true) { // Paging construct helper string sqlGetQuery = PagedQueryBuilder.PagedQuery(fullSqlQuery, filter, ref param); SqlMapper.GridReader reader = DbConnection.QueryMultiple(sqlGetQuery, param, CurrentTransaction); IEnumerable <TReturn> entity = reader.Read <TReturn>(buffered); int?totalCount = filter.IncludeMetadata ? reader.ReadSingleOrDefault <int?>() : null; return(new PaginatedList <TReturn>(entity, filter, totalCount)); }
/// <summary> /// Get PagedResultSet from a execute query with not nested object with/without TotalCount using the IncludeMetada /// </summary> /// <param name="fullSqlQuery">Sql Query to execute</param> /// <param name="filter">The SearchFilter </param> /// <param name="param">Parameters to blind with the sql query</param> /// <param name="buffered"></param> /// <returns></returns> public IPaginatedList <TReturn> ExecutePagedQuery <TReturn>(Type[] types, Func <object[], TReturn> map, string fullSqlQuery, ISearchFilter filter, object param = null, string splitOn = "id", bool buffered = true) { // Paging construct helper string sqlGetQuery = PagedQueryBuilder.PagedQuery(fullSqlQuery, filter, ref param); SqlMapper.GridReader reader = DbConnection.QueryMultiple(sqlGetQuery, param, CurrentTransaction); IList <TReturn> entity = (IList <TReturn>)reader.Read(types, map, splitOn, buffered); int?totalCount = filter.IncludeMetadata ? reader.ReadSingleOrDefault <int?>() : null; return(new PaginatedList <TReturn>(entity, filter, totalCount)); }
public static PagedResult <T> FetchPaged <T>(this DbConnection db, Action <IConfigureCommand> cfg, Pagination page, T anonModel = null) where T : class { typeof(T).Must(t => t != typeof(object), "Dynamic types are not supported"); var cmd = new CommandConfiguration(); cfg(cmd); var builder = new PagedQueryBuilder(db.GetPocoInfo <T>(), db.Provider()); var data = builder.Build(cmd.SqlText, cmd.Args, page); var result = new PagedResult <T>(); result.LongCount = db.GetValue <long>(c => c.Sql(data.CountSql, cmd.Args).WithCommandOptions(cmd.ApplyOptions)); if (result.Count == 0) { return(result); } result.Items = db.Fetch <T>(c => c.Sql(data.PagedSql, data.Args).WithCommandOptions(cmd.ApplyOptions)); return(result); }