簡體   English   中英

自動映射器映射子列表屬性

[英]Automapper to map child list properties

我試圖將一個視圖模型映射到如下所示的域:

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;}
}

viewModel

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.

我猜我在映射子屬性錯誤或什么? 任何見識將不勝感激。

您還需要從ProductVM到產品的映射

自動映射發現這些屬性匹配,但不知道如何來回映射它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM