namespace CSR.Infrastructure.Persistence; using Microsoft.EntityFrameworkCore; using CSR.Infrastructure.Persistence.Configurations; public class CSRDbContext(DbContextOptions options) : DbContext(options) { public DbSet Users { get; set; } public DbSet Roles { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.ApplyConfiguration(new UserConfiguration()); modelBuilder.ApplyConfiguration(new RoleConfiguration()); modelBuilder.Entity() .HasIndex(u => u.Username) .IsUnique(); modelBuilder.Entity() .HasOne(u => u.Role) .WithMany(r => r.Users) .HasForeignKey(u => u.RoleId); // --- Seed data --- // var adminRole = new Role { Id = 1, Name = "Admin" }; var userRole = new Role { Id = 2, Name = "User" }; modelBuilder.Entity() .HasData(adminRole, userRole); base.OnModelCreating(modelBuilder); } }