Entity Framework 6 - Missing table with only primary keys referencing different tables
Weak entities or join tables will not be generated by EF, you need to configure the relationships manually thru fluent API or using data annotations
As stated on Microsoft's website: under Relationship's convention:
Note: If you have multiple relationships between the same types (for example, suppose you define the
Person
andBook
classes, where thePerson
class contains theReviewedBooks
andAuthoredBooks
navigation properties and theBook
class contains theAuthor
andReviewer
navigation properties) you need to manually configure the relationships by using Data Annotations or the fluent API. For more information, see Data Annotations - Relationships and Fluent API - Relationships.
Refer to this link for more information
UPDATED
A workaround will work in case of EDMX ( but it cost maintenance) as follows:
- Remove the foreign keys from the join table in the database
- Update the EDMX from database
- Recreate the foreign keys in the join table
this workaround will work as long as you will not update your Model from the database again.
Recommended solution, keep everything as it was generated by EDMX and learn more about how to use crud operation for this case using the following links that were reported "helpful" by the user '@TravisWhidden'
- Insert/Update Many to Many Entity Framework . How do I do it?
- https://www.youtube.com/watch?v=uMQwORSTGX4 ( video)
As mentioned by @Hadi Hassan, EF will not “Expose” or recognize Relational Tables that are composed exclusively of other Entities.
Work Around:
If you only need to ‘READ’ the data you can
- Define a
view
in your Schema forTableB
. - Then do a
Model (.EDMX)
Update from DB (select the Update Views) - You will now be able to query your
TableB
data using your EF Context.
If you need to modify (Create,Update,Destroy) records in your TableB
Create Stored Procedures in your Schema, accordingly.
Import your Procs as Function into Your EF Model
You can now call those Functions from your model Context for the rest of your CRUD operations.