When using many-to-many with fluent api, EF creates an extra couple-table for primary keys. This table is not in DBSet<>, so how do I access this table within my code? Should I add it to DbSet<>, or should I define this table and must not leave EF to create it?
Asked
Active
Viewed 82 times
0
-
Please post your entities so that we can help better – Joakim Skoog Feb 02 '16 at 20:24
-
You only need to define the table if you are going to have non-key properties on it, otherwise just reference the collections on each side. – Steve Greene Feb 02 '16 at 20:27
-
TableA and TableB has their PKs with many-to-many. After Update-Database, EF create TableATableB table containing reference to each tables FKs. How do I access TableA's > TableB details by id via TableATableB. – Ozgur Erdogan Feb 02 '16 at 20:31
1 Answers
0
If you let the model as is, not declaring any relation entity between A and B, then you can't access that table. But maybe you don't need it, because you can use navigation properties (collections) from A to B and B to A.
So if you need all B's associated with A, you will use a.Bs, and vice versa.
You can achieve any desired query result between A and B even if you don't access the relation table, and you would need to declare that table only if you need to add extra data to the relation.

tede24
- 2,304
- 11
- 14