Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6863909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:50:44+00:00 2026-05-27T02:50:44+00:00

Hello. I have a list that looks like this one: public class PagedList<T> :

  • 0

Hello. I have a list that looks like this one:

public class PagedList<T> : List<T>
{
    public PagedList(IEnumerable<T> collection) : base(collection)
    { }
    public int TotalItems { get; set; }
    public int CurrentPage { get; set; }
    public int PageSize { get; set; }
    //some other properties
}

and used in repository for paging

 public PagedList<TEntity> GetPaged(int page)
 {
   var pagedEntities = some_query;
   return pagedEntities.AsPagedList(totalResults, page, pageSize);
 }

The same PagedList is also used in asp mvc view models for paging.
Is it possible to map this collections using Automapper with all the properties TotalItems/CurrentPage/… ?

   PagedList<DbItem> dbItems = _repository.GetPages(page);
   var viewItems = new PagedList<SomeItemView>();
   Mapper.Map(dbItems , viewItems);

Tahnk You !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:50:44+00:00Added an answer on May 27, 2026 at 2:50 am

    This worked for me. Are you looking for something more generic?

    public class DbItem
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
    
    public class ViewItem
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
    
    public class PagedList<T>: List<T>
    {
        public int TotalItems { get; set; }
        public int CurrentPage { get; set; }
        public int PageSize { get; set; }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            MapItems();
        }
    
        public static void MapItems()
        {
            Mapper.CreateMap<DbItem, ViewItem>();
            Mapper.CreateMap<PagedList<DbItem>, PagedList<ViewItem>>()
                .AfterMap((s, d) => Mapper.Map<List<DbItem>, List<ViewItem>>(s, d));
    
            var dbList = new PagedList<DbItem>
                             {
                                 new DbItem {Id = 1, Name = "a"}, 
                                 new DbItem {Id = 2, Name = "b"}
                             };
            dbList.TotalItems = 2;
            dbList.CurrentPage = 1;
            dbList.PageSize = 10;
            var viewList = Mapper.Map<PagedList<DbItem>, PagedList<ViewItem>>(dbList);
    
            Console.WriteLine(viewList.TotalItems);
            Console.WriteLine(viewList.CurrentPage);
            Console.WriteLine(viewList.PageSize);
            Console.WriteLine(viewList[0].Id + " " + viewList[0].Name);
            Console.WriteLine(viewList[1].Id + " " + viewList[1].Name);
            Console.ReadLine();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have this list that i am working on. When i move the
Hello I have 2 tables that look like this, What I wanting to is
I have a simple class called Tuple. which looks like this : class tuple
I have this list: dc = [hello, world] And this other: lines = [This
Hello i have a list view control, While the form is being loaded i
Hello I have the following code namespace ConsoleApplication2 { class Program { static void
Hello I have been having trouble with this for a while now. I have
I'm using org mode to make a list that I would like exported to
hello friends i have a check box list which contains all the courses kept
Hello I have created a filter for my list. In a template named _search.gsp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.