I decided to use .NET Core 2 and I am having issues. Microsoft documentation says navigation properties are no longer present in the base class IdentityUser, and I would like them back.
I can reference what role each user has in my view model, but when I put this into my application user class:
public virtual ICollection<IdentityUserRole<int>> Roles { get; } =
new List<IdentityUserRole<int>>();
public virtual ICollection<IdentityUserClaim<int>> Claims { get; } =
new List<IdentityUserClaim<int>>();
public virtual ICollection<IdentityUserLogin<int>> Logins { get; } =
new List<IdentityUserLogin<int>>();
and add this to my model builder:
builder.Entity<ApplicationUser>()
.HasMany(e => e.Claims)
.WithOne()
.HasForeignKey(e => e.UserId)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
builder.Entity<ApplicationUser>()
.HasMany(e => e.Logins)
.WithOne()
.HasForeignKey(e => e.UserId)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
builder.Entity<ApplicationUser>()
.HasMany(e => e.Roles)
.WithOne()
.HasForeignKey(e => e.UserId)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
I get the error The entity type 'IdentityUserLogin<int>' requires a primary key to be defined.
Relevant Microsoft documentation is here: https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x
How can I obtain the value of User.Role for display in my view?