38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using DrSousan.Api.Models;
|
|
|
|
namespace DrSousan.Api.Data;
|
|
|
|
public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
|
|
{
|
|
public DbSet<SiteSetting> SiteSettings => Set<SiteSetting>();
|
|
public DbSet<Service> Services => Set<Service>();
|
|
public DbSet<GalleryItem> GalleryItems => Set<GalleryItem>();
|
|
public DbSet<Testimonial> Testimonials => Set<Testimonial>();
|
|
public DbSet<BlogCategory> BlogCategories => Set<BlogCategory>();
|
|
public DbSet<BlogPost> BlogPosts => Set<BlogPost>();
|
|
public DbSet<Comment> Comments => Set<Comment>();
|
|
public DbSet<Faq> Faqs => Set<Faq>();
|
|
|
|
protected override void OnModelCreating(ModelBuilder mb)
|
|
{
|
|
mb.Entity<SiteSetting>()
|
|
.HasIndex(s => new { s.Section, s.Key })
|
|
.IsUnique();
|
|
|
|
mb.Entity<BlogPost>()
|
|
.HasIndex(b => b.Slug)
|
|
.IsUnique();
|
|
|
|
mb.Entity<BlogCategory>()
|
|
.HasIndex(c => c.Slug)
|
|
.IsUnique();
|
|
|
|
mb.Entity<Comment>()
|
|
.HasOne(c => c.Parent)
|
|
.WithMany(c => c.Replies)
|
|
.HasForeignKey(c => c.ParentId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
}
|