{"id":210,"date":"2020-09-17T13:20:15","date_gmt":"2020-09-17T13:20:15","guid":{"rendered":"http:\/\/tutorials.moedesign.de\/blog\/?p=210"},"modified":"2020-09-17T13:20:15","modified_gmt":"2020-09-17T13:20:15","slug":"automapper-returns-empty-collection-after-mapping","status":"publish","type":"post","link":"http:\/\/tutorials.moedesign.de\/blog\/automapper-returns-empty-collection-after-mapping\/","title":{"rendered":"Automapper returns empty Collection after mapping"},"content":{"rendered":"<p>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&lt;Product&gt; should be mapped to List&lt;ProductDTO&gt;. But the API always returned an empty list even if the source was filled correctly.<\/p>\n<p>Profile:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\nCreateMap&lt;Product, ProductDTO&gt;();\n\nCreateMap&lt;List&lt;Product&gt;, List&lt;ProductDTO&gt;&gt;();\n\n<\/pre>\n<p>The mistake was the second line in my profile class. Automapper\u00a0automatically maps collections you don&#8217;t have to create a map for this case.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&lt;Product&gt; should &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/tutorials.moedesign.de\/blog\/automapper-returns-empty-collection-after-mapping\/\" class=\"more-link\"><span class=\"screen-reader-text\">\u201eAutomapper returns empty Collection after mapping\u201c <\/span>weiterlesen<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3,4,6],"tags":[30,31,34,35],"class_list":["post-210","post","type-post","status-publish","format-standard","hentry","category-asp-net-core-mvc","category-aspnetcorewebapi","category-asp-net-mvc","category-csharp-2","tag-automapper","tag-collection","tag-empty","tag-error"],"_links":{"self":[{"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/posts\/210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/comments?post=210"}],"version-history":[{"count":0,"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/posts\/210\/revisions"}],"wp:attachment":[{"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/media?parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/categories?post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/tags?post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}