【发布时间】:2018-05-04 07:36:12
【问题描述】:
我正在尝试使用 razor 学习 asp.net 核心,并且我正在尝试创建一个视频游戏数据库来跟踪已完成的游戏、我还没有玩过的游戏等。
但是我有一个问题。我有一张桌子Game 和一张桌子Developer。因为一个游戏可以有很多开发者,而一个开发者可以有很多游戏,所以你制作了第三张桌子DeveloperXGame。
它们是这样的
public class Game
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Developer
{
public int Id { get; set; }
public string Name { get; set; }
}
public class DeveloperXGame
{
public int DeveloperId { get; set; }
public int JuegoId { get; set; }
public Developer Developer { get; set; }
public Game Game { get; set; }
}
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<Game> Game { get; set; }
public DbSet<Developer> Developer { get; set; }
public DbSet<DeveloperXGame> DeveloperXGame { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<DeveloperXGame>()
.HasKey(m => new { m.DeveloperId, m.GameId });
}
}
我已经为开发人员制作了页面,所以我首先手动创建它们。现在我正在尝试创建游戏,我想显示一个选择,我可以在其中选择该列表中的一个或多个开发人员(如果它们不存在,下一步将尝试通过游戏页面使用 ajax 添加它们) .但我已经迷失了这一点。
我不知道如何加载该列表中的开发者列表,稍后发布如何将这些选定的项目保存在表 DeveloperXGame 中。
谢谢
【问题讨论】:
标签: entity-framework razor asp.net-core