SHARE
TWEET

Untitled

a guest May 24th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   public class ApplicationUser : IdentityUser
  2.     {
  3.     }
  4.  
  5.    public class ApplicationRole : IdentityRole
  6. {
  7.     public ApplicationRole() : base() { }
  8.  
  9.     //
  10.     public virtual List<RolePermission> Permissions {get;set;}
  11. }
  12.  
  13. public class Permission
  14.     {
  15.     public int Id { get; set; }
  16.     public string Name { get; set; }
  17.     public virtual List<RolePermission> Roles { get; set; }
  18.     }
  19.  
  20. protected override void OnModelCreating(ModelBuilder builder)
  21.         {
  22.             base.OnModelCreating(builder);
  23.             // Customize the ASP.NET Identity model and override the defaults if needed.
  24.             // For example, you can rename the ASP.NET Identity table names and more.
  25.             // Add your customizations after calling base.OnModelCreating(builder);
  26.  
  27.     builder.Entity<Permission>()
  28.             .ToTable("AspNetPermissions")  
  29.             .HasKey(x => x.Id);
  30.  
  31.      
  32. builder.Entity<ApplicationRole>()
  33.         .ToTable("AspNetRoles")
  34.             .HasKey(x => x.Id);
  35.            
  36.  
  37. builder.Entity<RolePermission>()
  38.             .HasKey(x => new { x.RoleId, x.PermisionId });
  39.  
  40.  
  41.  
  42. builder.Entity<RolePermission>()
  43.             .HasOne(x => x.Role)
  44.             .WithMany(y => y.Permissions)
  45.             .HasForeignKey(y => y.RoleId);
  46.  
  47. builder.Entity<RolePermission>()
  48.             .HasOne(x => x.Permission)
  49.             .WithMany(y => y.Roles) //Aconselho renomear a propriedade para RolePermissions na classe Permission
  50.             .HasForeignKey(y => y.PermisionId);
  51.         }
  52.              
  53.        
  54.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top