当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Automapper: Missing type map configuration or unsupported mapping

问题描述:

I have the following code:

var data = repo.GetAll();

Mapper.CreateMap<Products_GetAll_Result, Product>();

return Mapper.Map<IEnumerable<Products_GetAll_Result>, List<FurnitureStore.Models.Product>>(data.ToList());

I get the following message in the exception:

{"Missing type map configuration or unsupported mapping.

Mapping types:

Products_GetAll_Result -> Product

FurnitureStore.DataLayer.Products_GetAll_Result -> FurnitureStore.Models.Product

Destination path:

List`1[0]

Source value:

FurnitureStore.DataLayer.Products_GetAll_Result"}

I tried anything I could think of but I can't get it to work. What am I doing wrong here?

网友答案:

EDIT

When you create your mapping

Mapper.CreateMap<Products_GetAll_Result, Product>();

Why are you not using FurnitureStore.Models.Product ? As when you are mapping you are using FurnitureStore.Models.Product rather than just Product class. (Assuming both classes are different)

EDIT

Removed the code which was redundant as OP's mapping style was correct

分享给朋友:
您可能感兴趣的文章:
随机阅读: