Entity Framework: Storing all contact details in the one table (association,compound FKs)
My database stores three types of user: Agent, Programmer and Employee. All three types of user will have an address, a telephone number, a fax number, etc..., so to minimize table count, I want to create a table tbContactDetails, and use this to store the contacts details of these 3 types of user.
My tbContactDetails, which looks like this:
tbContactDetails
int ContactId (PK, FK)
int ContactType (FK) (1=Agent, 2=Programmer, 3=Employee)
char (50) Addresses etc...
The field ContactType determines the type of owning user.
The Agent table would look like this:
tbAgent
int AgentId (PK)
int ContactId (FK)
int ContactType (FK) (which will always be 1 for an ag开发者_如何学运维ent)
char(50) Name etc...
So the three tables, tbAgent, tbProgrammer and tbEmployee would all have a FK that matches the tbContactDetails FK.
I can now create a Diagram in Server Explorer, linking the tbContactDetails FK to the tbAgent (FK), the tbProgrammer (FK) and the tbEmployee (FK).
My question is, and some of you may have seen this coming, how do I get Framework4 to recognise this FK2FK relationship, and creating associations for it?
Sorry this question is so long,
Terry.
It sounds like you will be using Table Per Type Inheritance. Have a look at this blog post, especially steps 5 and 6. In your case, tbContactDetails
would be the base entity and tbAgent
, tbProgrammer
, and tbEmployee
would be derived entities.
精彩评论