Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explicit many to many join table in Entity Framework 4

By default EF hides a many to many join table that does not contain additional data than the foreign keys to the joined tables.

Is it possible to tell EF (and the designer) to explicitly create the join table and make it usable in code?

Thanks

like image 576
Fabiano Avatar asked May 20 '11 10:05

Fabiano


People also ask

What is the difference between ICollection and list?

ICollection<T> is an interface, List<T> is a class.

How do I use navigation properties in Entity Framework?

A navigation property is an optional property on an entity type that allows for navigation from one end of an association to the other end. Unlike other properties, navigation properties do not carry data. A navigation property definition includes the following: A name.

How do you use a foreign key in code first approach?

To create Foreign Key, you need to use ForeignKey attribute with specifying the name of the property as parameter. You also need to specify the name of the table which is going to participate in relationship. I mean to say, define the foreign key table. Thanks for reading this article, hope you enjoyed it.


1 Answers

No EF designer will not add this entity for you. If you want junction table exposed you must manually delete created relation and add junction table's entity and two one-to-many FK relations. Here are related questions with step by step guide:

  • How to expose the join table in many to many relation
  • How to get Entity to Table mapping for many to many relations
like image 123
Ladislav Mrnka Avatar answered Oct 13 '22 20:10

Ladislav Mrnka