hanyadikhetvan-dotnethf/HanyadikHetVan/Data/ApplicationDbContext.cs
Torma Kristóf 10c1bb008f
All checks were successful
continuous-integration/drone/push Build is passing
final
2021-05-20 01:36:54 +02:00

39 lines
1.3 KiB
C#

using HanyadikHetVan.Data.Entities;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace HanyadikHetVan.Data
{
public class ApplicationDbContext : IdentityDbContext<User, IdentityRole, string>
{
public DbSet<Pause> Pauses { get; set; }
public DbSet<WeeklyTimeSpan> WeeklyTimeSpans { get; set; }
public DbSet<FunFact> FunFacts { get; set; }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
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);
}
}
}