system-praktyk-api/src/InternshipSystem.Repository/InternshipDbContext.cs

44 lines
1.4 KiB
C#

using Microsoft.EntityFrameworkCore;
using InternshipSystem.Core;
namespace InternshipSystem.Repository
{
public class InternshipDbContext : DbContext
{
public DbSet<Internship> Internships { get; set; }
public DbSet<Company> Companies { get; set; }
public DbSet<Edition> Editions { get; set; }
public DbSet<Report> Reports { get; set; }
public DbSet<Intern> Interns { get; set; }
public DbSet<InternshipType> InternshipTypes { get; set; }
public InternshipDbContext(DbContextOptions<InternshipDbContext> options)
: base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) =>
optionsBuilder
.UseSnakeCaseNamingConvention();
protected override void OnModelCreating(ModelBuilder modelBuilder) {
modelBuilder
.Entity<Internship>(ie => {
ie.OwnsOne(i => i.DeanAcceptance);
ie.OwnsOne(i => i.Insurance);
ie.OwnsOne(i => i.Mentor);
});
modelBuilder
.Entity<Company>()
.HasKey(c => c.Nip);
modelBuilder
.Entity<BranchOffice>()
.OwnsOne(b => b.Address);
modelBuilder
.Entity<Intern>()
.HasKey(i => i.AlbumNumber);
}
}
}