如何扩展 IdentityRoles 以使用扩展的 AspNetRoles 表?在 ASP MVC 5 中,使用 Identity 2.2 我看了here https://stackoverflow.com/q/40336574/6085193 & here https://stackoverflow.com/a/38429153/6085193答案对 DB First EF 没有帮助
Step 1:我扩展/添加了CompanyId
& DescRole
(使公司/租户的角色独一无二)
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:创建新角色是一个问题,现在我的创建角色失败,并且找不到扩展CompanyId
/Desc
上的属性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; }
}
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)