Automapper returns empty Collection after mapping

Some days ago I had a problem while mapping domain objects to DTO by automapper. My environment was an Asp.Net Core 3 Web Api project. I created an own profiles class where I stored my mapping logic. In the startup class I registered the mapper service. When running project my source of type List<Product> should be mapped to List<ProductDTO>. But the API always returned an empty list even if the source was filled correctly.

Profile:


CreateMap<Product, ProductDTO>();

CreateMap<List<Product>, List<ProductDTO>>();

The mistake was the second line in my profile class. Automapper automatically maps collections you don’t have to create a map for this case.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert