Initial ...
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user