public PagedData <Ability> GetPagedData(Dictionary <string, object> filters, string orderBy, int page, int pageSize) { // Create the list to return var returnValue = new PagedData <Ability>(); // Initialise templates SqlBuilder.Template selectTemplate; SqlBuilder.Template countTemplate; string timeElapsed; // Set the queries that we need to use var select = AbilitySql.PagedQuery.SelectAllFrom(AliasTs.Ability.Name, AliasTs.Ability.Alias); var count = AbilitySql.PagedQuery.CountAllFrom(AliasTs.Ability.Name, AliasTs.Ability.Alias); // Create the builder itself SqlBuilderRepository.CreateBuilder(filters, orderBy, page, pageSize, select, count, out selectTemplate, out countTemplate); // Count the number of records that were found var total = Query(s => s.Query <long>(countTemplate.RawSql, countTemplate.Parameters).Single(), out timeElapsed); // Mysql counts with bigint (long) so convert it to a 32-bit integer here returnValue.TotalRecords = Convert.ToInt32(total); // Get the page of data to send back to the controller returnValue.Data = Query(q => q.Query <Ability>(selectTemplate.RawSql, selectTemplate.Parameters), out timeElapsed); // Uncomment this if we really want to see how long it's taking, but by default, don't. //_logger.Debug(string.Format("GetSecuredPagedData: {0} records returned in {1}", returnValue.Data.Count(), timeElapsed)); // Done! return(returnValue); }
public async Task <PagedData <BossFight> > GetPagedDataAsync(Dictionary <string, object> filters, string orderBy, int offset, int pageSize, bool useOr = false) { // Create the list to return var returnValue = new PagedData <BossFight>(); // Initialise templates SqlBuilder.Template selectTemplate; SqlBuilder.Template countTemplate; // Set the queries that we need to use var select = MySQL.BossFight.PagedQuery.SelectAllFrom(AliasTs.BossFight); var count = MySQL.BossFight.PagedQuery.CountAllFrom(AliasTs.BossFight); // Create the builder itself SqlBuilderRepository.CreateBuilder(filters, orderBy, offset, pageSize, select, count, out selectTemplate, out countTemplate, useOr); var countTask = QueryAsync(q => q.QueryAsync <long>(countTemplate.RawSql, countTemplate.Parameters)); var recordTask = QueryAsync(q => q.QueryAsync(selectTemplate.RawSql, BossFight.Map, selectTemplate.Parameters)); // Wait for both tasks to finish await Task.WhenAll(countTask, recordTask); // Get the results from both tasks var total = countTask.Result.SingleOrDefault(); var records = recordTask.Result; // Mysql counts with bigint (long) so convert it to a 32-bit integer here returnValue.TotalRecords = Convert.ToInt32(total); // Get the page of data to send back to the controller returnValue.Data = records; return(returnValue); }