Map Many to Many relationship without navigation property

You can and this case must define the many-to-many relationship with Fluent API:

modelBuilder.Entity<User>()
    .HasMany(u => u.StarredWidgets)
    .WithMany() // <- no parameter here because there is no navigation property
    .Map(m =>
    {
        m.MapLeftKey("UserId");
        m.MapRightKey("WidgetId");
        m.ToTable("UserWidgets");
    });

Leave a Comment