[ADD] Join tables. Added attributes to role.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using DotBased.AspNet.Authority.EFCore.Models;
|
||||
using DotBased.AspNet.Authority.Models.Authority;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@@ -9,6 +10,10 @@ public class AuthorityContext(DbContextOptions<AuthorityContext> options) : DbCo
|
||||
public DbSet<AuthorityGroup> Groups { get; set; }
|
||||
public DbSet<AuthorityRole> Roles { get; set; }
|
||||
public DbSet<AuthorityUser> Users { get; set; }
|
||||
|
||||
public DbSet<RoleGroup> RoleGroup { get; set; }
|
||||
public DbSet<RoleUser> RoleUser { get; set; }
|
||||
public DbSet<UserGroup> UserGroup { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
@@ -29,6 +34,7 @@ public class AuthorityContext(DbContextOptions<AuthorityContext> options) : DbCo
|
||||
{
|
||||
roleEntity.ToTable("authority_roles");
|
||||
roleEntity.HasKey(x => x.Id);
|
||||
roleEntity.HasMany(r => r.Attributes).WithOne().HasForeignKey(a => a.BoundId).OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<AuthorityUser>(userEntity =>
|
||||
@@ -37,6 +43,24 @@ public class AuthorityContext(DbContextOptions<AuthorityContext> options) : DbCo
|
||||
userEntity.HasKey(x => x.Id);
|
||||
userEntity.HasMany(u => u.Attributes).WithOne().HasForeignKey(a => a.BoundId).OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<RoleGroup>(rgEntity =>
|
||||
{
|
||||
rgEntity.ToTable("role_group");
|
||||
rgEntity.HasKey(rg => new { rg.RoleId, rg.GroupId });
|
||||
});
|
||||
|
||||
modelBuilder.Entity<RoleUser>(ruEntity =>
|
||||
{
|
||||
ruEntity.ToTable("role_user");
|
||||
ruEntity.HasKey(ru => new { ru.RoleId, ru.UserId });
|
||||
});
|
||||
|
||||
modelBuilder.Entity<UserGroup>(ugEntity =>
|
||||
{
|
||||
ugEntity.ToTable("user_group");
|
||||
ugEntity.HasKey(ug => new { ug.UserId, ug.GroupId });
|
||||
});
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
|
Reference in New Issue
Block a user