0

私はMVCにかなり慣れていません。私はロールマネージャーとして働いています。この前に、ユーザー ID のデータ型を string から int に変更しました。今、私は自分のウェブサイトで役割を持ちたいと思っています。ページを作成し、その部分を実行するコードを追加しました。Web サイトを実行した後、Create New User Role をクリックすると、バックグラウンドで以下のエラーが発生します。これが私のコードです:

private List<SelectListItem> GetAllRolesAsSelectList()
    {
        List<SelectListItem> SelectRoleListItems =
            new List<SelectListItem>();

        var roleManager =
            new RoleManager<IdentityRole>(
                new RoleStore<IdentityRole>(new ApplicationDbContext()));

        var colRoleSelectList = roleManager.Roles.OrderBy(x => x.Name).ToList();

        SelectRoleListItems.Add(
            new SelectListItem
            {
                Text = "Select",
                Value = "0"
            });

        foreach (var item in colRoleSelectList)
        {
            SelectRoleListItems.Add(
                new SelectListItem
                {
                    Text = item.Name.ToString(),
                    Value = item.Name.ToString()
                });
        }

        return SelectRoleListItems;
    }

これはエラーがスローされる行です

var roleManager =
                new RoleManager<IdentityRole>(
                    new RoleStore<IdentityRole>(new ApplicationDbContext()));

これが私のIdentityModelページのコードです:

public class CustomUserRole : IdentityUserRole<int> 
{
}
public class CustomUserClaim : IdentityUserClaim<int> 
{ 
}
public class CustomUserLogin : IdentityUserLogin<int> 
{
}
public class CustomRole : IdentityRole<int, CustomUserRole>, IRole<int>
{
    public CustomRole() : base() { }
    public CustomRole(string name) 
        : this()
    { 
        this.Name = name; 
    }
}
public class CustomUserStore : UserStore<ApplicationUser, CustomRole, int,
    CustomUserLogin, CustomUserRole, CustomUserClaim>
{
    public CustomUserStore(ApplicationDbContext context)
        : base(context)
    {
    }
}
public class CustomRoleStore : RoleStore<CustomRole, int, CustomUserRole>
{
    public CustomRoleStore(ApplicationDbContext context)
        : base(context)
    {
    }
} 
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, CustomRole, 
int, CustomUserLogin, CustomUserRole, CustomUserClaim>  
{
    public ApplicationDbContext()
        : base("SMSGoConnection")
    {
    }
    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
    }

助けていただければ幸いです。

4

0 に答える 0