如何映射这样的列表?我的CreateMap会是什么样子?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、PageSize。
发布于 2011-09-04 06:19:38
无论你想出什么解决方案,都需要枚举你的原始列表。你可以这样做:
var modelList = new PagedList<UserModel>(
userList.Select(u => Mapper.Map<User, UserModel>(u)).AsQueryable(),
index, pageSize);https://stackoverflow.com/questions/7295316
复制相似问题