我試着去一個視圖模型映射到類似如下的域:Automapper映射子列表屬性
域
public class Category
{
public int CategoryId {get; set;}
public List<Product> Products {get; set;}
}
public class Product
{
public int ProductId {get; set;}
public int CategoryId {get; set;}
public Category Category {get; set;}
}
視圖模型
public class CategoryVM
{
public int CategoryId {get; set;}
public List<ProductVM> Products {get; set;}
}
public class ProductVM
{
public int ProductId {get; set;}
}
那麼這自動映射代碼:
Mapper.CreateMap<CategoryVM, Category>();
Category category = Mapper.Map<CategoryVM, Category>(_category);
它輕視的Products
屬性的錯誤:
Trying to map WebUI.ViewModel.ProductVM to Domain.Product. Using mapping configuration for WebUI.ViewModel.ProductVM to Domain.Product Destination property: Products Missing type map configuration or unsupported mapping. Exception of type 'AutoMapper.AutoMapperMappingException' was thrown.
即時猜測我映射子屬性錯了或什麼?任何洞察力將不勝感激。
可能重複[Problem auto mapping =>視圖模型集合而不是另一個視圖模型](http://stackoverflow.com/questions/5691270/problem-auto-mapping-collection-of-view-models-instead-另一個視圖模型) – 2012-11-12 21:26:43