57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using xIdentityModels;
|
|
using xIdentityModels.Models;
|
|
using xIdentityModels.Navigations;
|
|
|
|
namespace xIds.DbContext
|
|
{
|
|
public class XIdentityDbContext : IdentityDbContext
|
|
{
|
|
//
|
|
#region Props/DbSets ...
|
|
public DbSet<XToken> Tokens { get; set; }
|
|
public DbSet<XDevice> Devices { get; set; }
|
|
public DbSet<XProfileImage> Avatars { get; set; }
|
|
public DbSet<XBannedDevice> BannedDevices { get; set; }
|
|
public DbSet<XFriendshipFollower> Followers { get; set; }
|
|
public DbSet<XFriendshipFollowing> Followings { get; set; }
|
|
public DbSet<XVerificationRequest> VerificationRequests { get; set; }
|
|
#endregion
|
|
|
|
public XIdentityDbContext(DbContextOptions<XIdentityDbContext> options) : base(options)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
Database.EnsureCreated();
|
|
Database.Migrate();
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
//
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
//
|
|
// Fix XUser GUID Generator on Add ...
|
|
modelBuilder
|
|
.Entity<IdentityUser>()
|
|
.Property(e => e.Id)
|
|
.ValueGeneratedOnAdd();
|
|
|
|
//
|
|
// Handle Role List ...
|
|
modelBuilder.Entity<XUser>(u =>
|
|
{
|
|
u.HasMany(x => x.Roles)
|
|
.WithOne()
|
|
.HasForeignKey(ur => ur.UserId)
|
|
.IsRequired();
|
|
});
|
|
}
|
|
}
|
|
} |