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 Tokens { get; set; } public DbSet Devices { get; set; } public DbSet Avatars { get; set; } public DbSet BannedDevices { get; set; } public DbSet Followers { get; set; } public DbSet Followings { get; set; } public DbSet VerificationRequests { get; set; } #endregion public XIdentityDbContext(DbContextOptions 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() .Property(e => e.Id) .ValueGeneratedOnAdd(); // // Handle Role List ... modelBuilder.Entity(u => { u.HasMany(x => x.Roles) .WithOne() .HasForeignKey(ur => ur.UserId) .IsRequired(); }); } } }