【发布时间】:2012-02-17 23:56:27
【问题描述】:
我有一个客户 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);
}
【问题讨论】:
标签: asp.net-mvc entity-framework automapper