I have this Generic Pagination class: i want to map PagedList<Caste> to PagedList<CasteModel>
public class PagedList<T>
{
public PagedList()
{
}
public PagedList(IList<T> source, int pageNumber, int pageSize)
{
this.TotalItems = source.Count;
this.PageNumber = pageNumber;
this.PageSize = pageSize;
this.Items = source;
}
public int TotalItems { get; set; }
public int PageNumber { get; set; }
public int PageSize { get; set; }
public IEnumerable<T> Items { get; set; }
public int TotalPages => (int)Math.Ceiling(this.TotalItems / (double)this.PageSize);
}
And Model and View Model Classes
public class Caste
{
public int Id { get; set; }
public string CasteCode { get; set; }
public string CasteDesc { get; set; }
public bool IsActive { get; set; }
public int? CasteParentId { get; set; }
public virtual Caste CasteParent { get; set; }
public virtual ICollection<Caste> CasteChildren { get; set; }
public virtual ICollection<Customer> Customers { get; set; }
}
public class CasteModel
{
public int Id { get; set; }
public string CasteCode { get; set; }
public string CasteDesc { get; set; }
public bool IsActive { get; set; }
public int? CasteParentId { get; set; }
}
and below is my auto mapper configuration
public class AppProfile : Profile
{
public AppProfile()
{
//Masters
CreateMap<CasteModel, Caste>();
CreateMap<Caste, CasteModel>();
CreateMap(typeof(PagedList<>), typeof(PagedList<>));
// CreateMap<PagedList<Caste>, PagedList<CasteModel>>(); ---This also checked
}
This is the code for mapping in controller
PagedList<Caste> result = new PagedList<Caste>
{
Items = new List<Caste> { new Caste { Id = 7, CasteCode="" } },
TotalItems = 1
};
var pagedListOfDtos = Mapper.Map<PagedList<CasteModel>>(result);
When executing below error am getting below exception
"Mapper not initialized. Call Initialize with appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using ProjectTo or UseAsDataSource extension methods, make sure you pass in the appropriate IConfigurationProvider instance."
Am using Asp.net core and automapper 6.1. Code is written based on below link generic list to automapper Please suggest a me solution tried a lot all getting same message