Junction Tables: Changing many-to-many to one-to-many in Entity Framework model
I've got a set of tables as below:
PositionShiftPattern
PositionShiftPatternID PositionIDEmployeePositionShiftPattern
EmployeePositionShiftPatternID EmployeePositionIDTemplateShiftPattern
TemplateShiftPatternIDWeek
WeekIDPositionShiftPatternJunction
PositionShiftPatternID WeekIDEmployeePositionShiftPatternJunction
EmployeePositionShiftPatternID WeekIDTemplateShiftPatternJunction
TemplateShiftPatternID WeekID
So PositionShiftPattern, EmployeePositionShiftPattern and TemplateShiftPattern each have a junction to Week, with one-to-many relationships inbetween.
Obviously EF will map the relationships between PositionShiftPattern, EmployeePositionShiftPattern and TemplateShiftPattern and Week as many-to-many and create navigation properties from each table directly to Week.
Is it possible to then change the many-to-many relationships to one-to-many relationships (e.g. each Week should map to a single ShiftPattern)? I'm trying to achieve mutual exclusion (see diagram below) and want to avoid just adding PositionShiftPatternID, EmployeePositionShiftPatternID and TemplateShiftPatternID to Week. Should I be looking at another开发者_JAVA技巧 way of achieving mutual exclusion?
Thanks
No it is not possible. The relation must be the same as in the database. If you create one-to-many relation it will be considered as a new one and you will have to add those Ids to week. Also when looking at your model it doesn't make sense to introduce such relation. At the moment Shift can be related to many weeks and week can have many shifts. If you introduce one-to-many it will mean that each week instance can have only one shift.
精彩评论