Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ApplicationUser : IdentityUser
- {
- }
- public class ApplicationRole : IdentityRole
- {
- public ApplicationRole() : base() { }
- //
- public virtual List<RolePermission> Permissions {get;set;}
- }
- public class Permission
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public virtual List<RolePermission> Roles { get; set; }
- }
- protected override void OnModelCreating(ModelBuilder builder)
- {
- base.OnModelCreating(builder);
- // Customize the ASP.NET Identity model and override the defaults if needed.
- // For example, you can rename the ASP.NET Identity table names and more.
- // Add your customizations after calling base.OnModelCreating(builder);
- builder.Entity<Permission>()
- .ToTable("AspNetPermissions")
- .HasKey(x => x.Id);
- builder.Entity<ApplicationRole>()
- .ToTable("AspNetRoles")
- .HasKey(x => x.Id);
- builder.Entity<RolePermission>()
- .HasKey(x => new { x.RoleId, x.PermisionId });
- builder.Entity<RolePermission>()
- .HasOne(x => x.Role)
- .WithMany(y => y.Permissions)
- .HasForeignKey(y => y.RoleId);
- builder.Entity<RolePermission>()
- .HasOne(x => x.Permission)
- .WithMany(y => y.Roles) //Aconselho renomear a propriedade para RolePermissions na classe Permission
- .HasForeignKey(y => y.PermisionId);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement