我有一个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);
}