I am making an hours calendar using MVC’s Code First approach. This is the data-structure from the bottom-up:
All classes contain table element ID’s.
A DaySpec contains opening and closing times for a day.
A WeekSpec contains, among trivial Booleans, an array of DaySpecs.
An ExceptionHoursSet, which defines hours that are exceptions to a general hours pattern, contains an integer RepCount and an object HoursSet; RepCount specifying how many times the exception is repeated, and the HoursSet being either a DaySpec or a WeekSpec.
A Schedule contains a string Name, a WeekSpec which specifies the general pattern on a weekly basis, and an IEnumerable of ExceptionHoursSets.
Right.
So my question is, using the WeekSpec class both in Schedule and ExceptionHoursSet, can I share it between the two in the database structure? How would I set up the EF relationships?
Sure they can!
If you are doing this using Entity Framework’s Code First approach, you would simply include the foreign key relationships as types within a class:
I may have left a few properties out, but you get the idea (fill in where necessary). There are different ways you can approach this situation (lazy-loading, etc. . .), it is all really dependent on exactly what you need to do with the data.