We are learning Entity Framework 6.1 (from NuGet) as we move away from Linq2Sql. We have a small handful of tables that associate two separate tables like shown below.
EF6 Database First generation
When in Visual studios, blank class library, doing a Database First EF6 EDMX file, the diagram only generates TableA and TableC -- the TableB does not get generated.
Visual Studios View:
You can see that only TableA and TableC are created. Technically TableB should have been created, because you would want to be able to manage those references.
The Association between A and C shown in the diagram:
I feel like I am missing an option, or misunderstanding a key concept of Entity Framework. Any idea how to have the missing TableB generated with the T4? The EDMX file does show it, but for some reason it doesn't get generated into a .CS file with the two properties indicating the relationship.
The primary reason we need this, is we extended the EF6 T4 template to add some factory patterns to match our existing models. Because it doesnt generate a class for TableB, we dont get the autogenerated code that we are looking for.
Thoughts / suggestions? Thanks.
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
Bookclasses, where the
Personclass contains the
AuthoredBooksnavigation properties and the
Bookclass contains the
Reviewernavigation 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
A workaround will work in case of EDMX ( but it cost maintenance) as follows:
this workaround will work as long as you will not update your Model from 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 was reported "helpful" by the user '@TravisWhidden'