Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8280601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:44:12+00:00 2026-06-08T09:44:12+00:00

I am making an hours calendar using MVC’s Code First approach. This is the

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:44:16+00:00Added an answer on June 8, 2026 at 9:44 am

    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:

    public class DaySpec
    {
        public int DaySpecId { get; set; }
    
        public DateTime Open { get; set; }
    
        public DateTime Close { get; set; }
    }
    
    public class WeekSpec
    {
        public int WeekSpecId { get; set; }
    
        public bool booleanOne { get; set; }
    
        public DaySpec[] DaySpecs { get; set; }
    }
    
    public class ExceptionHoursSet
    {
        public int ExceptionHoursSetId { get; set; }
    
        public int RepCount { get; set; }
    
        public int WeekSpecId { get; set; } // set which WeekSpec you are referencing below (for lazy-loading)
    
        public virtual WeekSpec HoursSet { get; set; }
    
        // etc . . .
    }
    
    public class Schedule
    {
        public int ScheduleId { get; set; }
    
        public string Name { get; set; }
    
        public int WeekSpecId { get; set; } // set which WeekSpec you are referencing below (for lazy-loading)
    
        public virtual WeekSpec WeekSpec { get; set; }
    
        public IEnumerable<ExceptionHoursSet> ExceptionHoursSets { get; set; } 
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Making my first steps in RIA Services (VS2010Beta2) and i encountered this problem: created
I've been trying for hours and I cannot solve this problem. I'm making an
First off, I will say i've spent 6 hours on this topic and have
I lost last 3 hours trying to do this. Im making an app that
I recently read this article from Neil Griffin Making Distinctions Between Different Kinds of
So, I have this bit of wild, crazy code, that is making the compiler
Making an adobe flex ui in which data that is calculated must use proprietary
I am moving from the basic authentication method using username and password to the
I have been struggling for the last few hours trying to get this search
I've already spent countless hours puzzling over this, utilizing Google searches and other Stack

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.