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?
Asked
Active
Viewed 1,163 times
1 Answers
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