如何映射這樣的列表?我的CreateMap將如何看待?對於PagedList類看起來是這樣的:Automapper和PagedList
public interface IPagedList
{
int TotalCount
{
get;
set;
}
int PageIndex
{
get;
set;
}
int PageSize
{
get;
set;
}
bool IsPreviousPage
{
get;
}
bool IsNextPage
{
get;
}
}
public class PagedList<T> : List<T>, IPagedList
{
public PagedList(IQueryable<T> source, int index, int pageSize)
{
this.TotalCount = source.Count();
this.PageSize = pageSize;
this.PageIndex = index;
this.AddRange(source.Skip(index * pageSize).Take(pageSize).ToList());
}
public PagedList(List<T> source, int index, int pageSize)
{
this.TotalCount = source.Count();
this.PageSize = pageSize;
this.PageIndex = index;
this.AddRange(source.Skip(index * pageSize).Take(pageSize).ToList());
}
public PagedList()
{
}
public int TotalCount
{
get;
set;
}
public int PageIndex
{
get;
set;
}
public int PageSize
{
get;
set;
}
public bool IsPreviousPage
{
get
{
return (PageIndex > 0);
}
}
public bool IsNextPage
{
get
{
return (PageIndex * PageSize) <= TotalCount;
}
}
}
我的映射代碼:
Mapper.CreateMap<User, UserModel>();
var model = Mapper.Map<PagedList<User>, PagedList<UserModel>>(users); // Not quite sure about this.
當我做以上,只有列表被映射,其他屬性,如TOTALCOUNT,每頁,沒有映射。
'User'和'UserModel'類是怎麼樣的?這就是你最終想要映射的內容,而且你沒有顯示任何內容。 –
@Darin Dimitrov他們可以是任何東西,他們正常映射,只是當我把它們放在這PagedList中的問題。 –
本主題正是討論這個問題: http://stackoverflow.com/questions/2070850/can-automapper-map-a-paged-list – ekenman