Files

27 lines
793 B
C#

using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System;
using Abstractions.Entities;
namespace Server
{
public class AppDbContext(DbContextOptions<AppDbContext> options)
: IdentityDbContext<User, IdentityRole<long>, long>(options)
{
public override DbSet<User> Users { get; set; }
public DbSet<Card> Cards { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<User>()
.HasMany(u => u.Cards)
.WithOne(c => c.User)
.HasForeignKey(c => c.UserId)
.OnDelete(DeleteBehavior.Cascade);
base.OnModelCreating(builder);
}
}
}