Entity Framework Code First Many to Many Setup For Existing Tables

前端 未结 1 1059
清酒与你
清酒与你 2020-12-03 14:28

I have the following tables Essence, EssenseSet, and Essense2EssenceSet

Essense2EssenceSet is the linking table t

相关标签:
1条回答
  • 2020-12-03 15:13

    Remove your Essence2EssenceSet model class. If junction table contains only keys of related entities participating in many-to-many relations it is not needed to map it as entity. Also make sure that your fluent mapping of many-to-many relations specifies schema for table:

    mb.Entity<Essence>()
      .HasMany(e => e.EssenceSets)
      .WithMany(set => set.Essences)
      .Map(mc =>
          {
              mc.ToTable("Essence2EssenceSet", "Com");
              mc.MapLeftKey("EssenceID");
              mc.MapRightKey("EssenceSetID");
          });
    
    0 讨论(0)
提交回复
热议问题