J.W.
J.W.

Reputation: 18181

What's the name convention of many to many tables in EF

I have many to many relationship between table A and table B, at the beginning, the generated relationship table is AB, however, after a few updates, now the name change to BA, I want to avoid that. I know you can use FluentConfiguration .ToTable to specify the name, but is there a better way to do that?

Upvotes: 4

Views: 1282

Answers (1)

Slauma
Slauma

Reputation: 177153

The default name AB or BA most likely depends on the order in which the DbSets of the two entities are declared in the context class, on other entities that refer to the two entities and in which order their metadata get loaded into the context. Results from a few tests are here.

In other words the name could swap from one to the other whenever you change soemthing in your model or context class during development and it is hard to control.

Specifying the name with Fluent API is the best way to have a stable link table name that doesn't change - and as far as I can tell, it is the only way.

Upvotes: 5

Related Questions