mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using API.Entities;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace API.Data
|
|
{
|
|
public class DataContext : IdentityDbContext<AppUser, AppRole, int,
|
|
IdentityUserClaim<int>, AppUserRole, IdentityUserLogin<int>,
|
|
IdentityRoleClaim<int>, IdentityUserToken<int>>
|
|
{
|
|
public DataContext(DbContextOptions options) : base(options)
|
|
{
|
|
|
|
}
|
|
public DbSet<Library> Library { get; set; }
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
{
|
|
base.OnModelCreating(builder);
|
|
|
|
builder.Entity<AppUser>()
|
|
.HasMany(ur => ur.UserRoles)
|
|
.WithOne(u => u.User)
|
|
.HasForeignKey(ur => ur.UserId)
|
|
.IsRequired();
|
|
|
|
builder.Entity<AppRole>()
|
|
.HasMany(ur => ur.UserRoles)
|
|
.WithOne(u => u.Role)
|
|
.HasForeignKey(ur => ur.RoleId)
|
|
.IsRequired();
|
|
}
|
|
}
|
|
} |