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

前端 未结 1 1419
挽巷
挽巷 2021-01-06 14:47

I\'m using Identity 2.1 to handle the user roles in my asp.net application. So far so good, i created new context extending from IdentityDBContext, extending the IdentityUse

1条回答
  •  生来不讨喜
    2021-01-06 15:05

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

    public class UserStore : UserStore, IUserStore, IUserStore, 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 : UserStore, IUserStore, IUserStore, 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 : UserStore
        where TUser : IdentityUser, new()
        where TRole : IdentityRole, new()
        where TContext : DbContext
    {
        public UserStore(TContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
    }
    

    0 讨论(0)
提交回复
热议问题