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 7722969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:19:39+00:00 2026-06-01T04:19:39+00:00

Im having a problem with the design of my Models. The application has Modules

  • 0

Im having a problem with the design of my Models. The application has Modules (I.e. University modules) which are taught by one or many Lecturers, Lecturers can also teach one or many Modules, therefore in terms of database design there is a Many-to-many relationship between Modules and Lecturers, hence in my database this relationship will be represented by an addition table that has Module_id and Lecturer_id as a composite key to achieve this I included a list of lecturers in the module class with the virtual modifier and visa versa, as seen below

public class Module
{
    public int id { get; set; }
    public string name { get; set; }
    public Department department { get; set; }
    public string code { get; set; }
    public virtual List<Lecturer> lecturers { get; set; }

    ...
}

And the lecturer class:

public class Lecturer
{

    public int id { get; set; }
    public string name { get; set; }
    public virtual List<Module> modules { get; set; }

    ...
}

My first question is, is this the best way to implement this situation in the Models? It seems to work ok, however this means that Modules have Lecturers which teach Modules which then Taught by the Lecturers… and so on, and hence seems very inefficient and not optimal. It also means that I cannot simply return, for example a Module as a JSON object to the browser because of this loop.

Finally, if this is the correct implementation is there a way using LINQ to query for a Module and then return a limited Module that has Lecturers but then the Lectures are restricted and do not have modules associated with them? At the moment I am using the following statement?

Module module = dbContext.Modules.Where(r => r.id == id).Single();
  • 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-01T04:19:40+00:00Added an answer on June 1, 2026 at 4:19 am

    Personally, when dealing with many-to-many relationships, I like to make the relationship table a concrete part of my model. That is, I would have a LecturerModule table that both Lecturer and Module reference. In a many-to-many relationship, the relationship is a thing. This makes the most architectural sense for me and makes models so much easier to work with rather than trying to hide the relationship in some sort of complex looped tree.

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

Sidebar

Related Questions

This is a WPF/C# application and I'm having more of a design problem than
I’m having a problem getting the data from my database which I created to
Are there any patterns/solutions to solve the problem of having an API call which
I encountered a code design problem while working on a small application. In terms
I have this problem where I need to design a Java package which is
I'm making my first site with Django, and I'm having a database design problem.
I've self-taught myself all of my web design skills and now I'm having a
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
I'm having problem when running my Windows Forms program. In the program, I have
I'm having problem with Rails plugin attachment_fu . On every upload, I get validation

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.