How can I extend the IdentityRoles to work with an extended AspNetRoles Table? in ASP MVC 5, with Identity 2.2 I looked here & here the answers do not help with DB First EF
Step 1: I extended/added the CompanyId
& DescRole
(to make Role unique by company/tenant)
CREATE TABLE [dbo].[AspNetRoles] // EXTENDED role table
[Id] [nvarchar](50) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[Description] [nvarchar](50) NOT NULL, // EXTENDED
[CompanyId] [nvarchar](50) NOT NULL, // EXTENDED Company/Tenant
Step 2: Create new Role is an issue, now my create role fails, and I cannot find the extended CompanyId
/Desc
properties on the IdentityRole
(its a dbFirst EF strategy
)
//Create ROle Class
public ActionResult CreateRole(FormCollection collection)
{
try {
var context = new ApplicationDbContext();
// RoleStore
// var newRole = new AspNetRoles();
// ontext.Roles.Add(new ApplicationRole) { // not visible...
context.Roles.Add(new Microsoft.AspNet.Identity.EntityFramework.IdentityRole()
{
Name = collection["RoleName"],
});
context.SaveChanges();
ViewBag.Message = "Role created successfully !";
...
//Extended Role Class
public class ApplicationRole : IdentityRole
{
public ApplicationRole() : base() { }
public ApplicationRole(string name) : base(name) { }
public string Description { get; set; }
public string CompanyId { get; set; }
}