95 lines
3.3 KiB
C#
95 lines
3.3 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using InternshipSystem.Core;
|
|
using InternshipSystem.Core.Entity;
|
|
using InternshipSystem.Core.Entity.Internship;
|
|
using InternshipSystem.Core.UglyOrmArtifacts;
|
|
|
|
namespace InternshipSystem.Repository
|
|
{
|
|
public class InternshipDbContext : DbContext
|
|
{
|
|
public DbSet<Company> Companies { get; set; }
|
|
public DbSet<Edition> Editions { get; set; }
|
|
public DbSet<StaticPage> StaticPages { get; set; }
|
|
public DbSet<InternshipType> InternshipTypes { get; set; }
|
|
public DbSet<Student> Students { get; set; }
|
|
public DbSet<Course> Courses { 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<BranchOffice>()
|
|
.OwnsOne(bo => bo.Address);
|
|
|
|
|
|
modelBuilder.Entity<InternshipRegistration>()
|
|
.OwnsOne(ir => ir.Mentor);
|
|
|
|
modelBuilder.Entity<DocumentScan>(builder =>
|
|
{
|
|
builder
|
|
.HasKey(scan => scan.DocumentId);
|
|
|
|
builder
|
|
.HasOne(s => s.Document)
|
|
.WithOne(d => d.Scan);
|
|
});
|
|
|
|
modelBuilder.Entity<ProgramSubject>(builder =>
|
|
{
|
|
builder
|
|
.HasKey(subject => new { InternshipProgramId = subject.InternshipRegistrationId, subject.InternshipSubjectId });
|
|
|
|
builder
|
|
.HasOne(k => k.Registration)
|
|
.WithMany(model => model.Subjects)
|
|
.HasForeignKey(subject => subject.InternshipRegistrationId);
|
|
|
|
builder
|
|
.HasOne(k => k.Subject)
|
|
.WithMany()
|
|
.HasForeignKey(subject => subject.InternshipSubjectId);
|
|
});
|
|
|
|
modelBuilder.Entity<EditionInternshipType>(builder =>
|
|
{
|
|
builder
|
|
.HasKey(type => new { type.EditionId, type.InternshipTypeId});
|
|
|
|
builder
|
|
.HasOne(k => k.Edition)
|
|
.WithMany(model => model.AvailableInternshipTypes)
|
|
.HasForeignKey(p => p.EditionId);
|
|
|
|
builder
|
|
.HasOne(k => k.InternshipType)
|
|
.WithMany()
|
|
.HasForeignKey(type => type.InternshipTypeId);
|
|
});
|
|
|
|
modelBuilder.Entity<EditionSubject>(builder =>
|
|
{
|
|
builder
|
|
.HasKey(subject => new { subject.EditionId, subject.InternshipSubjectId});
|
|
|
|
builder
|
|
.HasOne(k => k.Edition)
|
|
.WithMany(model => model.AvailableSubjects)
|
|
.HasForeignKey(p => p.EditionId);
|
|
|
|
builder
|
|
.HasOne(k => k.Subject)
|
|
.WithMany()
|
|
.HasForeignKey(subject => subject.InternshipSubjectId);
|
|
});
|
|
}
|
|
}
|
|
} |