Updating Identity in ASP.NET Core 2.0

Mark G

I'm having an issue trying to replace IdentityUser navigation properties in ASP.NET Core Identity which was a breaking change in 2.0 update.

I looked at Add IdentityUser POCO Navigation Properties, but there was scant explanation on how to actually do this.

In ApplicationUser.cs I added the following:

public virtual ICollection<IdentityUserRole<string>> Roles
    { get; } = List<IdentityUserRole<string>>();

But when I attempted to use that navigation property it used ApplicationUserId instead of UserId.

Any suggestions would be welcome as this isn't intuitive, hopefully the identity team can further elaborate in the documentation.

Mark G

Adding the following to OnModelCreating in ApplicationDbContext.cs fixed the problem for me which I found from GitHub issue How to include Roles in IdentityUser?

builder.Entity<ApplicationUser>().HasMany(p => p.Roles)
    .WithOne().HasForeignKey(ur => ur.UserId).IsRequired();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive