Files
Kayori_Medusa.net/Core/Server/AppDbConetext.cs
T
2025-06-22 13:01:34 +02:00

27 lines
785 B
C#

using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Server.Entities;
using System;
namespace Server
{
public class AppDbContext(DbContextOptions<AppDbContext> options)
: IdentityDbContext<User, IdentityRole<int>, int>(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);
}
}
}