Many-to-many relationship in the Entity Framework, where do you have more than two fields in the join table?

I am importing a database into the Entity Framework and I am having many-to-many relationship issues that look like this:

I understand that if the join table (middle) contains only two fields (foreign keys), then EF will automatically delete the middle table and create a many-to-many relationship. Unfortunately, I have no control over the database schema, so does anyone know if there is a way to replicate this behavior manually?

There is no target for this Id field in Employee_Employee_Type, it is simply poorly designed.

+6
c # database entity-framework entity-framework-4
source share
2 answers

According to the recipes of Entity Framework 4, p. 554, here is how you do it (this is not very).

Essentially, you want to create a View Employee_Employee_type mapping table, but without an extra column, and then manually map it to two other tables. Below are photos of the relevant pages. I think (and hope!) That applies to academic free use copyright laws ...

The book is fantastic, by the way, so I would recommend buying it. I hope this will push me to the author, if he happens to this.

enter image description here

enter image description here

+8
source share

Yes, this is probably the best approach to give you a cleaner experience on request, and you can always use a link table to insert and update. In the end, it will not be mentioned when EF will support payload navigation properties. I am glad that people love work. It honestly took 1 year to write a book.

+2
source share

All Articles