Let’s take as an example 3 entities being page (a webpage), a link and an area. The relations go as follow.
Page *—-* Link *—-* Area
Which textually means :
• A page has many links
• A link can be in many page
• A link can be in many areas
• An area can contain many links
Which means, if I am not mistaking would require 4 tables. 3 for each entity and one relational table that would contain the the primary keys of each entities.
Is there a way to generate this kind of table with code-first?
Thank you,
First, no. A junction table does not have to have primary keys at all. It just needs foreign keys. If you want to make them primary keys, you can, but it does not need to be.
Second, there’s no such thing as 3 primary keys. There can only be one primary key, but it may span several columns. This is called a Composite Primary Key. You would only need a primary key if you need to uniquely identify each row. I typically use either no primary key, or i use a synthetic primary key (if i have a payload in the join table).
Third, No. What you are describing would use 5 tables. Page, Link, Area, PageLink, and LinkArea. Area does not relate to Page in the model you present, other than through Link.
EDIT: I don’t think you have thought through your data model thoroughly. Can an Area be in many pages? Or is an Area only in one page? Can a Link be in both pages and areas?
EDIT: based on your comments, what you want is this then.
This requires 6 tables. Page, Link, Area, PageLink, PageArea, AreaLink