using BGC.Server.DataLayer.Entities; using Microsoft.EntityFrameworkCore; namespace BGC.Server.DataLayer { public class BgcDbContext : DbContext { public DbSet Games { get; set; } public DbSet Genres { get; set; } public DbSet Authors { get; set; } public DbSet Owners { get; set; } public DbSet Ratings { get; set; } public DbSet Themes { get; set; } public DbSet GameOwners { get; set; } public BgcDbContext(DbContextOptions options) : base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { entity.HasKey(e1 => e1.Id); entity .HasMany(e => e.Themes) .WithMany(e => e.Games) .UsingEntity(); entity .HasMany(e => e.Genres) .WithMany(e => e.Games) .UsingEntity(); entity .HasMany(e => e.Authors) .WithMany(e => e.Games) .UsingEntity(); entity .HasMany(e => e.Owners) .WithMany(e => e.Games) .UsingEntity(); }); modelBuilder.Entity(entity => { entity.HasKey(e1 => new { e1.GameId, e1.OwnerId }); entity.HasOne(e => e.Game).WithMany(e => e.GameOwners); entity.HasOne(e => e.Owner).WithMany(e => e.GameOwners); }); modelBuilder.Entity(entity => { entity.HasKey(e1 => new { e1.GameId, e1.AuthorId }); entity.HasOne(e => e.Game).WithMany(e => e.GameAuthors); entity.HasOne(e => e.Author).WithMany(e => e.GameAuthors); }); modelBuilder.Entity(entity => { entity.HasKey(e1 => new { e1.GameId, e1.ThemeId }); entity.HasOne(e => e.Game).WithMany(e => e.GameThemes); entity.HasOne(e => e.Theme).WithMany(e => e.GameThemes); }); modelBuilder.Entity(entity => { entity.HasKey(e1 => new { e1.GameId, e1.GenreId }); entity.HasOne(e => e.Game).WithMany(e => e.GameGenres); entity.HasOne(e => e.Genre).WithMany(e => e.GameGenres); }); modelBuilder.Entity(entity => { entity.HasKey(e1 => new { e1.GameId, e1.RatingTypeId }); entity.HasOne(e => e.Game).WithMany(e => e.GameRatings); entity.HasOne(e => e.RatingType).WithMany(e => e.GameRatings); }); modelBuilder.Entity(entity => { entity.HasKey(e1 => e1.Id); }); modelBuilder.Entity(entity => { entity.HasKey(e1 => e1.Id); }); modelBuilder.Entity(entity => { entity.HasKey(e1 => e1.Id); entity .HasMany(e => e.Games) .WithMany(e => e.Owners) .UsingEntity(); }); modelBuilder.Entity(entity => { entity.HasKey(e1 => e1.Id); }); modelBuilder.Entity(entity => { entity.HasKey(e1 => e1.Id); }); } } }