35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using NexusReader.Domain.Entities;
|
|
|
|
namespace NexusReader.Infrastructure.Persistence;
|
|
|
|
public class AppDbContext : IdentityDbContext<NexusUser>
|
|
{
|
|
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
|
|
{
|
|
}
|
|
|
|
public DbSet<SemanticKnowledgeCache> SemanticKnowledgeCache => Set<SemanticKnowledgeCache>();
|
|
public DbSet<Ebook> Ebooks => Set<Ebook>();
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
modelBuilder.Entity<SemanticKnowledgeCache>(entity =>
|
|
{
|
|
entity.HasKey(e => e.ContentHash);
|
|
entity.HasIndex(e => e.ContentHash).IsUnique();
|
|
});
|
|
|
|
modelBuilder.Entity<Ebook>(entity =>
|
|
{
|
|
entity.HasOne(e => e.User)
|
|
.WithMany(u => u.Ebooks)
|
|
.HasForeignKey(e => e.UserId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
});
|
|
}
|
|
}
|