Files
zpc-bulletin-board/ZpcBulletinBoard/Data/ApplicationDbContext.cs
David Štaleker c4883e4296 dev
2024-03-10 18:58:24 +01:00

43 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using ZpcBulletinBoard.Models;
using ZpcBulletinBoard.Models.Editor;
namespace ZpcBulletinBoard.Data
{
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: IdentityDbContext<IdentityApplicationUser, IdentityApplicationRole, int>(options)
{
public DbSet<Note> Notes { get; set; }
public DbSet<BulletinBoard> BulletinBoards { get; set; }
public DbSet<BulletinBoardPage> BulletinBoardPage { get; set; }
public DbSet<BulletinBoardPageLink> BulletinBoardPageLinks { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
//Relacije
modelBuilder.Entity<BulletinBoard>()
.HasMany(t => t.Links)
.WithOne(t => t.BulletinBoard)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<BulletinBoardPage>()
.HasMany(t => t.Links)
.WithOne(t => t.BulletinBoardPage)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<BulletinBoardPage>()
.HasMany(t => t.Notes)
.WithOne(t => t.BulletinBoardPage)
.OnDelete(DeleteBehavior.Cascade);
}
}
}