小编SOK*_*SOK的帖子

AutoMapper:一对多 -> 多对多

我对 AutoMapper 还很陌生。我很难将 AutoMapper 配置为能够将UserViewModel多个映射TagViewModel为多对多关系 ( RecipeEntity <-> TagEntity),这是 Entity Framework Core 所需UserAndTagEntity的连接表。

数据对象:

public class TagEntity
{
    public string Name { get; set; }

    public virtual ICollection<UserAndTagEntity> UserAndTags { get; set; } = new List<UserAndTagEntity>();
}

public class UserEntity
{
    public string Name { get; set; }

    public virtual ICollection<UserAndTagEntity> UserAndTags { get; set; } = new List<UserAndTagEntity>();
}

public class UserAndTagEntity
{
    public int Id { get; set; }
    public virtual …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework automapper entity-framework-core

2
推荐指数
1
解决办法
4303
查看次数