开发者

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

PositionID

EmployeePositionShiftPattern

EmployeePositionShiftPatternID

EmployeePositionID

TemplateShiftPattern

TemplateShiftPatternID

Week

WeekID

PositionShiftPatternJunction

PositionShiftPatternID

WeekID

EmployeePositionShiftPatternJunction

EmployeePositionShiftPatternID

WeekID

TemplateShiftPatternJunction

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?

Junction Tables: Changing many-to-many to one-to-many in Entity Framework model

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜