Automapper 字典属性

Automapper Dictionary Properties

我正在尝试使用 AutoMapper 在具有字典 属性 的 class 之间进行映射,但我不确定如何继续。

这是地图两侧 classes 的简单表示

public class Person {
    public string Name {get;set;}
    public Dictionary<string, Post> Posts {get;set;}
}

public class Post {
    public string PostName {get;set;}
}

创建地图如下:

Mapper.CreateMap<Api.Entities.Person, App.Entities.Person>();

错误结果:

Missing type map configuration or unsupported mapping.
Mapping types:

Post -> Post
Api.Entities.Post -> App.Entities.Post

Destination path: Person.Posts.Posts.Posts0[0]
Source value: Api.Entities.Post

您还需要为 Post 实体创建一个映射器。基本上,错误是说您在 Person 内部使用 Post,但找不到映射 Post 属性.

的方法
Mapper.CreateMap<Api.Entities.Post, App.Entities.Post>();