public async Task <PagingModel <ProfileDto> > GetProfiles(ProfileFilter filter, int page, int pageSize)
        {
            Query baseQuery = new Query().From("Profiles");

            if (filter != null)
            {
                baseQuery.WhereFilter(filter);
            }

            Query profilesQuery = baseQuery.Clone().Select("FirstName", "LastName", "MiddleName", "Birthday");

            profilesQuery.Offset((page - 1) * pageSize);

            profilesQuery.Limit(pageSize);

            Query totalQuery = baseQuery.Clone().AsCount("Id");

            SqlResult result = compiler.Compile(new Query[] { profilesQuery, totalQuery });

            using (IDbConnection connection = dbConnectionFactory.CreateConnection())
            {
                using (SqlMapper.GridReader reader = await connection.QueryMultipleAsync(result.Sql, result.NamedBindings))
                {
                    return(new PagingModel <ProfileDto>
                    {
                        Items = await reader.ReadAsync <ProfileDto>(),
                        Total = await reader.ReadSingleAsync <int>()
                    });
                }
            }
        }
Beispiel #2
0
 public virtual Task <object> ReadSingleAsync() => _gridReader.ReadSingleAsync();