How to Extend Microsoft.AspNet.Identity.EntityFramework.IdentityRole

前端 未结 2 616
情话喂你
情话喂你 2021-01-03 15:13

I want to be able to extend the default implementation of IdentityRole to include fields like Description. It\'s easy enough to do this for IdentityUser because IdentityDbCo

2条回答
  •  攒了一身酷
    2021-01-03 15:23

    UserManager uses UserStore as its user store (IUserStore). UserManager works with UserStore for adding and removing user to a role name as IUserRole.

    Likewise, there are interfaces IRole & IRoleStore for IdentityRole and RoleStore where TRole is IdentityRole. This is to work plainly with Roles directly.

    So you can inherit IdentityRole and add additional information. Use RoleStore to manage it along additional information.

    RoleManager provides core interaction methods for Role, which can use MyRoleStore.

    MyIdentityRole.cs

    public class MyIdentityRole: IdentityRole
    {
       public String Description { get; set;}
    }
    

提交回复
热议问题