Files
6d486f49 ffaab59585 ...
2026-09-09 17:19:03 -04:00

32 lines
935 B
C#

using Microsoft.EntityFrameworkCore;
using Model;
namespace API.Data;
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
}
public DbSet<User> Users { get; set; } = default!;
public DbSet<CardNote> CardNotes { get; set; } = default!;
public DbSet<UserDeck> UserDecks { get; set; } = default!;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>(b => { b.HasKey(u => u.Username); });
modelBuilder.Entity<CardNote>(b => { b.HasKey(n => new { n.Username, n.CardName }); });
modelBuilder.Entity<UserDeck>(b =>
{
b.HasKey(d => d.Id);
if (Database.IsNpgsql())
{
b.Property(d => d.Cards).HasColumnType("jsonb");
b.Property(d => d.Divers).HasColumnType("jsonb");
}
});
}
}