I\'m trying to finish updating to .NET Core 2.0 but a couple of errors pop up:
The problem:
I have two classes, ApplicationRole and ApplicationU
ICollection
, ICollection
and ICollection
navigation properties have been removed from Microsoft.AspNetCore.Identity.IdentityUser
.
You should define them manually
public class MyUser : IdentityUser
{
public virtual ICollection> Roles { get; } = new List>();
public virtual ICollection> Claims { get; } = new List>();
public virtual ICollection> Logins { get; } = new List>();
}
To prevent duplicate foreign keys when running EF Core Migrations, add the following to your IdentityDbContext
class' OnModelCreating
method
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity()
.HasMany(e => e.Claims)
.WithOne()
.HasForeignKey(e => e.UserId)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
builder.Entity()
.HasMany(e => e.Logins)
.WithOne()
.HasForeignKey(e => e.UserId)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
builder.Entity()
.HasMany(e => e.Roles)
.WithOne()
.HasForeignKey(e => e.UserId)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
}
Migrating Authentication and Identity to ASP.NET Core 2.0