Map Many to Many relationship without navigation property

前端 未结 1 1310
面向向阳花
面向向阳花 2020-11-30 06:25

Is is possible to map a many to many relationship without having a navigation property on one of the ends? For example I have some widgets and some users who can star partic

相关标签:
1条回答
  • 2020-11-30 06:37

    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");
        });
    
    0 讨论(0)
提交回复
热议问题