using FAuth.DataBase.Tables;
using Microsoft.EntityFrameworkCore;
namespace FAuth.DataBase
{
///
/// 数据库
///
public class FAuthDb:DbContext
{
public FAuthDb(DbContextOptions options) : base(options) {
Database.EnsureCreatedAsync().Wait();
}
protected override void OnModelCreating(ModelBuilder modelBuilder) {
var mb = modelBuilder;
mb.Entity().HasKey(m => new { m.AppId,m.RoleGroupId });
mb.Entity().HasKey(m => new { m.RoleGroupId,m.RoleId });
mb.Entity().HasKey(m => new { m.RoleId,m.UserId });
base.OnModelCreating(modelBuilder);
}
///
/// 用户
///
public DbSet Users { get; set; }
///
/// 应用信息
///
public DbSet Apps { get; set; }
///
/// 角色组信息
///
public DbSet RoleGroups { get; set; }
///
/// 角色信息
///
public DbSet Roles { get; set; }
///
/// 应用角色组对应关系
///
public DbSet App_RoleGroups { get; set; }
///
/// 角色组角色对应关系
///
public DbSet RoleGroup_Roles { get; set; }
///
/// 角色用户对应关系
///
public DbSet Role_Users { get; set; }
}
}