mirror of
https://github.com/hmaxnl/DotBased.git
synced 2025-02-23 07:05:01 +01:00
[ADD] Join tables. Added attributes to role.
This commit is contained in:
parent
2938e1311f
commit
65d625a30d
|
@ -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);
|
||||
}
|
||||
|
|
7
DotBased.AspNet.Authority.EFCore/Models/RoleGroup.cs
Normal file
7
DotBased.AspNet.Authority.EFCore/Models/RoleGroup.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace DotBased.AspNet.Authority.EFCore.Models;
|
||||
|
||||
public class RoleGroup
|
||||
{
|
||||
public Guid RoleId { get; set; }
|
||||
public Guid GroupId { get; set; }
|
||||
}
|
7
DotBased.AspNet.Authority.EFCore/Models/RoleUser.cs
Normal file
7
DotBased.AspNet.Authority.EFCore/Models/RoleUser.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace DotBased.AspNet.Authority.EFCore.Models;
|
||||
|
||||
public class RoleUser
|
||||
{
|
||||
public Guid RoleId { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
}
|
7
DotBased.AspNet.Authority.EFCore/Models/UserGroup.cs
Normal file
7
DotBased.AspNet.Authority.EFCore/Models/UserGroup.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace DotBased.AspNet.Authority.EFCore.Models;
|
||||
|
||||
public class UserGroup
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public Guid GroupId { get; set; }
|
||||
}
|
|
@ -1,24 +1,18 @@
|
|||
namespace DotBased.AspNet.Authority.Models.Authority;
|
||||
|
||||
public class AuthorityGroup
|
||||
public class AuthorityGroup()
|
||||
{
|
||||
public AuthorityGroup(string name) : this()
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public AuthorityGroup()
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
CreatedDate = DateTime.Now;
|
||||
}
|
||||
|
||||
public Guid Id { get; set; }
|
||||
|
||||
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
public string? Name { get; set; }
|
||||
|
||||
public long Version { get; set; }
|
||||
|
||||
public DateTime CreatedDate { get; set; }
|
||||
public DateTime CreatedDate { get; set; } = DateTime.Now;
|
||||
public ICollection<AuthorityAttribute> Attributes { get; set; } = [];
|
||||
}
|
|
@ -15,5 +15,7 @@ public class AuthorityRole()
|
|||
|
||||
public DateTime CreatedDate { get; set; } = DateTime.Now;
|
||||
|
||||
public IEnumerable<AuthorityAttribute> Attributes { get; set; } = [];
|
||||
|
||||
public override string ToString() => Name ?? string.Empty;
|
||||
}
|
Loading…
Reference in New Issue
Block a user