Search code examples
c#asp.netasp.net-identity

.NET Core 2.0 User no longer has roles


I found this github announcement: https://github.com/aspnet/Announcements/issues/263

But I'm not quite sure what it means. I'm almost done migrating my .NET 1.1.4 app over to 2.0.0, but I'm having issues with Roles not being in the User. So I have a class that extends IdentityUser. But I am guessing that IdentityUser no longer has Roles so I'd have to put getters/setters to my class to set it back in right?


Solution

  • "If you were using these navigation properties, you will need to add them back to your application specific user class."

    What this means is if you want to continue using the navigation properties (including the Roles property on IdentityUser) you need to add them manually, they will no longer be inherited automatically

    So just go to your class where you have your user, for example you may have a class like this:

    public class ApplicationUser : IdentityUser { ... }

    and add the property there, like so:

    /// <summary>
    /// Navigation property for the roles this user belongs to.
    /// </summary>
    public virtual ICollection<TUserRole> Roles { get; } = new List<TUserRole>();
    

    According to Hao Kung this should allow you to continue using the Roles property on IdentityUser.