如何将相关实体添加到多对多关系

问题描述

假设我有这样的实体:

    public class Game
    {
        public int Id { get; set; }       

        public ICollection<GamePlatform> GamePlatforms { get; set; }

        // ↓ This one should be filled ↓
        public ICollection<Platform> Platforms { get; set; }
        // ↑ This one should be filled ↑
    }

    public class Platform
    {
        public int Id { get; set; }       

        public ICollection<GamePlatform> GamePlatforms { get; set; }

        // ↓ This one should be filled ↓
        public ICollection<Game> Games { get; set; }
        // ↑ This one should be filled ↑
    }

    public class GamePlatform
    {
        public int GameId { get; set; }
        public Game Game { get; set; }

        public int PlatformId { get; set; }
        public Platform Platform { get; set; }
    }

我想避免创建额外的实体和/或后端代码。 我可以仅通过 OnModelCreating 方法进行配置吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)