I am building a relationship between 2 tables (code first [entity framework]). But I have the following issue:
The table Employees saves the employees with different positions (engineers, technicians, salesmen, etc).
In the table project, I have 3 relations with the table employees:
- Manager = Employee with the engineer position
- Technician = Employee with the technician position
- Saleman (EmployeeId) = Employee with the saleman position
Is it possible to create more than one relationship between two tables with EntityFrameWork or do I need to do this (i'm not sure about this).
However, I going to create a table for the positions related with Employees.
CodePudding user response:
If you have 3 Fk in your project table... You can set 3 Fk with fluent api...
modelBuilder.Entity<product>()
.HasOne<employees>(s => s.Eng)
.WithMany(g => g.progectEng)
.HasForeignKey(s => s.ProjectEngFK);
modelBuilder.Entity<product>()
.HasOne<employees>(s => s.Tech)
.WithMany(g => g.progectTech)
.HasForeignKey(s => s.ProjectTechFK);