EF Core Many to Many with Identity User not working

Viewed 106

So if I understand correctly, EF Core 5.0 updated how to make your many to many relationship. I wanted to try this out using IdentityUser & Tournament classes. Here is the code that I have.

Tournament Class:

public class Tournament
{
   public int Id { get; set; }
   public string Title { get; set; }

   public ICollection<AppUser> Participants { get; set; }
}

IdentityUser Class (I have tried to set the id as int too)

public class AppUser : IdentityUser
{
    public ICollection<Tournament> RegisteredTournaments;
}

In my Startup class:

services.AddIdentity<AppUser, IdentityRole>()
                .AddEntityFrameworkStores<DataContext>();

And lastly, my DbContext class (AppUsers out of comments changes nothing)

 public class DataContext : IdentityDbContext<AppUser>
 {
    //public DbSet<AppUser> AppUsers { get; set; }
    public DbSet<Tournament> Tournaments { get; set; }

    public DataContext(DbContextOptions options) : base(options)
    {
    }

    protected override void OnModelCreating(ModelBuilder builder)
    {
       base.OnModelCreating(builder);
    }
}

But now, when I add this migration, it will only add a FK 'TournamentId' into the AspNetUsers table. Anything I can do to properly implement this?

Thanks in advance, Janne

0 Answers
Related