InkForge/shared/InkForge.Data/NoteDbContext.cs

38 lines
844 B
C#
Raw Normal View History

2024-02-07 22:16:59 +01:00
using Microsoft.EntityFrameworkCore;
namespace InkForge.Data;
public class NoteDbContext(
2024-04-05 12:31:34 +02:00
DbContextOptions options
2024-02-07 22:16:59 +01:00
) : DbContext(options)
{
public DbSet<Blob> Blobs { get; set; } = default!;
2024-02-16 02:24:25 +01:00
public DbSet<MetadataEntity> Metadata { get; set; } = default!;
2024-02-07 22:16:59 +01:00
public DbSet<NoteEntity> Notes { get; set; } = default!;
2024-04-05 12:31:34 +02:00
public NoteDbContext(DbContextOptions<NoteDbContext> options) : this((DbContextOptions)options)
{ }
2024-02-07 22:16:59 +01:00
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
2024-02-16 02:24:25 +01:00
modelBuilder.Entity<MetadataEntity>(options =>
{
options.HasKey(m => m.Id);
});
2024-02-07 22:16:59 +01:00
modelBuilder.Entity<NoteEntity>(options =>
{
options.HasKey(m => m.Id);
2024-05-02 21:44:13 +02:00
options.OwnsOne(m => m.Value, m =>
{
m.HasOne<Blob>().WithOne().HasForeignKey<Note>(m => m.ContentId).IsRequired();
});
2024-04-05 12:31:34 +02:00
options.HasOne(m => m.Parent);
2024-02-07 22:16:59 +01:00
});
}
}