4

When I create two entities with many to many relationship, it will generate a relationship table in the database, is it possible to specify the table's name?

James
  • 2,570
  • 7
  • 34
  • 57

1 Answers1

4

Yes but you have to use fluent API:

mb.Entity<FirstEntity>()
  .HasMany(a => a.SecondEntities)
  .WithMany(b => b.FirstEntities)
  .Map(mc =>
      {
          mc.ToTable("YourTableName", "YourDbSchema");
          mc.MapLeftKey("FirstEntityKeyColumnName");
          mc.MapRightKey("SecondEntityKeyColumnName");
      });
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • +1, however it would be good to specify the version of EF for which this is true (a year later I do not know if the needs for fluent API still applies). Thanks. – rufo Apr 08 '13 at 18:36