我试着去一个视图模型映射到类似如下的域: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