我有一個Customers EF POCO類,其中包含對地址表的引用。使用自動映射器映射嵌套對象
以下代碼似乎可行,但我不確定它是否是最乾淨的方式。有沒有更好的方法來映射這隻使用一個Map調用?
[HttpGet]
public ActionResult Details(string ID)
{
BusinessLogic.Customers blCustomers = new BusinessLogic.Customers("CSU");
DataModels.Customer customer = blCustomers.GetCustomer(ID);
CustomerDetailsViewModel model = new CustomerDetailsViewModel();
Mapper.CreateMap<DataModels.Customer, CustomerDetailsViewModel>();
Mapper.CreateMap<DataModels.Address, CustomerDetailsViewModel>();
Mapper.Map(customer, model);
Mapper.Map(customer.Address, model);
return View(model);
}