Is it possible to define a many-to-many relationship in Entity Framework 4.1 (Code First approach) using Data Annotations only, without model builder?
For example, something like:
Product = { Id, Name, ... }
Category = { Id, Name, ... }
ProductCategory = { ProductId, CategoryId }
You get the picture.
I don't want to have an intermediate entity ProductCategory
in the context with two many-to-ones since I don't have any additional data, just the two FKs. Also, I should be able to define table name for the intermediate table for use with an existing database.
It is possible to define many-to-many with default conventions or with data annotations but it is not possible to change mapping to junction table (table's name and columns) without model builder. Simple many-to-many:
For using annotations you can use:
If you need to control mapping of junction table to existing database you need
modelBuilder
. Data annotations are not as powerful as fluent API.