hanyadikhetvan-dotnethf/HanyadikHetVan/Data/ApplicationDbContext.cs

39 lines
1.3 KiB
C#
Raw Permalink Normal View History

2021-05-03 01:30:06 +02:00
using HanyadikHetVan.Data.Entities;
2021-05-19 17:56:56 +02:00
using Microsoft.AspNetCore.Identity;
2021-05-03 01:30:06 +02:00
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace HanyadikHetVan.Data
{
2021-05-19 17:56:56 +02:00
public class ApplicationDbContext : IdentityDbContext<User, IdentityRole, string>
2021-05-03 01:30:06 +02:00
{
public DbSet<Pause> Pauses { get; set; }
public DbSet<WeeklyTimeSpan> WeeklyTimeSpans { get; set; }
2021-05-19 17:56:56 +02:00
public DbSet<FunFact> FunFacts { get; set; }
2021-05-19 04:33:53 +02:00
2021-05-03 01:30:06 +02:00
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
2021-05-20 01:36:54 +02:00
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Pause>()
.HasOne(s => s.WeeklyTimeSpan)
.WithMany(s => s.Pauses)
.OnDelete(DeleteBehavior.ClientCascade);
modelBuilder.Entity<FunFact>()
.HasOne(s => s.WeeklyTimeSpan)
.WithMany(s => s.FunFacts)
.OnDelete(DeleteBehavior.ClientCascade);
modelBuilder.Entity<WeeklyTimeSpan>()
.HasOne(s => s.User)
.WithMany(s => s.WeeklyTimeSpans)
.OnDelete(DeleteBehavior.ClientCascade);
}
2021-05-03 01:30:06 +02:00
}
}