0

How is it possible to use the same foreign key for different tables

enter image description here

I have these tables, users have one to zero or one relation to member, admins and employers table.

Both admins and employers can create new jobs(one to many with jobs table) while members can only apply for jobs(many to many with jobs table). As you can see, I have Id as the primary key for these tables, and in my Jobs table, I have Id as the foreign key which is related to all 3 tables(members/admins/employers)

Is it possible to use the same foreign key for these tables? Because when I am adding a new job, entity framework couldn't figure out which table is the Id foreign key related to, because all of them uses the same key.

Mindless
  • 2,352
  • 3
  • 27
  • 51
  • 1
    one practical suggestion is to have a UserType column in Users table and also in Jobs table. Then have a FK relationship between Jobs and Users with columns (id, UserType). Makes sense? – NP3 Nov 10 '14 at 06:55
  • If I remember correctly, when you create the foreign keys for your table you can call them something like `MemberId`, `AdminId` or `EmployerId` and then map it to their `Id` field in their corresponding table, that would fix your problem... – Kutyel Nov 10 '14 at 07:26
  • @kutyel that would also add additional blank columns – Mindless Nov 10 '14 at 22:50

0 Answers0