AddToRole and IdentityRole is not part of the model for the current context

余生颓废 提交于 2019-11-30 23:07:00

okay so the problem was with the UserStore, the default declaration was

public class UserStore<TUser> : UserStore<TUser, IdentityRole, string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>, IUserStore<TUser>, IUserStore<TUser, string>, IDisposable where TUser : Microsoft.AspNet.Identity.EntityFramework.IdentityUser {

which have IdentityRole explicitly declared instead of making it using the generic notation like TUser, so we just need to create another class extending from the parent UserStore:

public class CarbonUserStore<TUser> : UserStore<TUser, Role, string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>, IUserStore<TUser>, IUserStore<TUser, string>, IDisposable where TUser : Microsoft.AspNet.Identity.EntityFramework.IdentityUser {

    public CarbonUserStore(DbContext context) :base(context) {}     }

Not cool Microsoft, I spent a day trying to figure it wait. However, it's added in the Identity package shipping with vNext(gotta love it bering open source): https://github.com/aspnet/Identity/blob/dev/src/Microsoft.AspNet.Identity.EntityFramework/UserStore.cs

public class UserStore<TUser, TRole, TContext> : UserStore<TUser, TRole, TContext, string>
    where TUser : IdentityUser, new()
    where TRole : IdentityRole, new()
    where TContext : DbContext
{
    public UserStore(TContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!