我已经在ASP中将字符串key更改为int key。. NET身份在我的项目。当我们想通过字符串键创建角色时,我们可以写
public class AppRole : IdentityRole {
public AppRole() : base() { }
public AppRole(string name) : base(name) { }
}
//IdentityRole class is for ASP.NET Identity
public class IdentityRole : IdentityRole<string, IdentityUserRole>
{
public IdentityRole();
public IdentityRole(string roleName);
}
有一个接受参数作为角色名的构造函数。但是当我想通过int键创建角色时,没有用于传递角色名称的构造函数。
public class Role : IdentityRole<int, UserRole>
{
public Role() : base() { }
}
public class UserRole : IdentityUserRole<int>
{
}
//IdentityRole<TKey, TUserRole> class is for ASP.NET Identity
public class IdentityRole<TKey, TUserRole> : IRole<TKey> where TUserRole : global::Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole<TKey>
{
public IdentityRole();
public TKey Id { get; set; }
public string Name { get; set; }
public virtual ICollection<TUserRole> Users { get; }
}
我想使用IdentityResult result = await RoleManager.CreateAsync(new Role(name));
来创建一个角色,但是我必须在role, new role (name)的实例中传递一个角色名称。这是不可能的。我该怎么做呢?
IdentityResult result = await RoleManager.CreateAsync(new Role { Name = roleName });