c# - Entity Framework 6 - Missing table with only primary keys referencing different tables -


we learning entity framework 6.1 (from nuget) move away linq2sql. have small handful of tables associate 2 separate tables shown below.

ef6 database first generation

db diagram:

enter image description here

schema overview:

enter image description here

when in visual studios, blank class library, doing database first ef6 edmx file, diagram generates tablea , tablec -- tableb not generated.

enter image description here

visual studios view:

enter image description here

you can see tablea , tablec created. technically tableb should have been created, because want able manage references.

the association between , c shown in diagram:

enter image description here

i feel missing option, or misunderstanding key concept of entity framework. idea how have missing tableb generated t4? edmx file show it, reason doesn't generated .cs file 2 properties indicating relationship.

the primary reason need this, extended ef6 t4 template add factory patterns match our existing models. because doesnt generate class tableb, dont autogenerated code looking for.

thoughts / suggestions? thanks.

weak entities or join tables not generated ef, need configure relationships manually thru fluent api or using data annotations

as stated on microsoft's website: under relationship's convention:

note: if have multiple relationships between same types (for example, suppose define person , book classes, person class contains reviewedbooks , authoredbooks navigation properties , book class contains author , reviewer navigation properties) need manually configure relationships using data annotations or fluent api. more information, see data annotations - relationships , fluent api - relationships.

refer link more information

updated

a workaround work in case of edmx ( cost maintenance) follows:

  1. remove foreign keys join table in database
  2. update edmx database
  3. recreate foreign keys in join table

this workaround work long not update model database again.

recommended solution, keep generated edmx , learn more how use crud operation case using following links reported "helpful" user '@traviswhidden'

  1. insert/update many many entity framework . how do it?
  2. https://www.youtube.com/watch?v=umqworstgx4 ( video)

Comments