InkForge/shared/InkForge.Data/NoteDbContext.cs

35 lines
745 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);
options.OwnsOne(m => m.Value);
2024-04-05 12:31:34 +02:00
options.HasOne(m => m.Parent);
2024-02-07 22:16:59 +01:00
});
}
}