DeathwatchDbContext.cs 878 B

12345678910111213141516171819202122232425262728293031323334
  1. using Domain;
  2. using Domain.Weapons;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace DataLayer;
  5. public class DeathwatchDbContext : DbContext
  6. {
  7. public DbSet<Player> Players { get; set; }
  8. public DbSet<Weapon> Weapons { get; set; }
  9. public DeathwatchDbContext() : base()
  10. {
  11. }
  12. public DeathwatchDbContext(DbContextOptions<DeathwatchDbContext> options) : base(options)
  13. {
  14. }
  15. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  16. {
  17. if (!optionsBuilder.IsConfigured)
  18. {
  19. //optionsBuilder.UseSqlServer("Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=ReadersDB");
  20. }
  21. }
  22. protected override void OnModelCreating(ModelBuilder modelBuilder)
  23. {
  24. modelBuilder.Entity<Player>().HasMany(s => s.Weapons);
  25. modelBuilder.Entity<Weapon>().HasMany(w => w.Players);
  26. }
  27. }