에 두 개체에서 매핑 할 필요가 :나는 다음과 같은 개체 모델을 가지고 하나 하나
public class Project
{
[Key]
public int ProjectID { get; set; }
public string Title { get; set; }
public string Slug { get; set; }
public string Content { get; set; }
public string Category { get; set; }
public string Client { get; set; }
public int Year { get; set; }
// more attributes here...
}
내가 (내보기에 대한 구체적인) 뷰 모델을 준비하고 싶습니다. 프로젝트의
- 목록
- 페이징 정보
public class ProjectListViewModel
{
public IEnumerable<ProjectInfos> ProjectList { get; set; }
public PagingInfo Paging { get; set; }
public class ProjectInfos
{
public string Title { get; set; }
public string Slug { get; set; }
public string Content { get; set; }
public string Category { get; set; }
public string Client { get; set; }
public int Year { get; set; }
}
public class PagingInfo
{
public int TotalItems { get; set; }
public int ItemsPerPage { get; set; }
public int CurrentPage { get; set; }
public int TotalPages { get; set; }
}
}
, 나는이 다른 개체와를 작성하여 뷰 모델을 준비하고 싶은 다음은 뷰 모델이다
내 컨트롤러는 다음과 같습니다.
public ViewResult List(string category, int page = 1)
{
IEnumerable<Project> projectList = m_Business.GetProjects(category, page, 10);
PagingInfo pagingInfo = m_Business.GetPagingInfo(category, page, 10);
// Here I need to map !!
ProjectListViewModel viewModel = .....
return View(viewModel);
}
컨트롤러에서 어떻게 진행할 수 있습니까? 나는 우리가 한 객체에서 다른 객체로 매핑하기 위해 automapper를 사용할 수 있다는 것을 알고 있지만 이지만 여기서는 두 객체에서 단일 객체로 매핑해야합니다.
감사합니다.
중복 가능성 [? 여러 집계 뿌리를 가진보기 모델을 처리하는 방법 (http://stackoverflow.com/questions/2020499/how-to- :
그런 다음 당신은 다음과 같은 코드를 사용할 수 있습니다 handle-view-model-with-multiple-aggregate-roots) –