public PageList <TDto> GetRecordByPage <TEntity, TDto>(PageRequest page) where TEntity : class { var criteria = this.Session.CreateCriteria <TEntity>(); page.PrepareCriteria(ref criteria); page.PrepareOrder(ref criteria); var list = criteria.SetFirstResult(page.GetFirstResult()) .SetMaxResults(page.GetMaxResults()) .List <TEntity>() .ToList(); criteria = this.Session.CreateCriteria <TEntity>(); page.PrepareCriteria(ref criteria); var mapper = new AutoMapper.MapperConfiguration(cfg => { cfg.CreateMap <TEntity, TDto>(); }).CreateMapper(); int total = criteria.SetProjection(Projections.RowCount()).UniqueResult <int>(); return(new PageList <TDto>(mapper.Map <List <TDto> >(list), total)); }