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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:31:24+00:00 2026-05-27T11:31:24+00:00

I have a model like this: Client – which has many Locations – which

  • 0

I have a model like this:

Client – which has many Locations – which can have many Teams, a sort of one-to-many-to-many relationship.

I can find lots of examples of one-to-many relationships, but none like this.

The question is: how do I get back a Client object with all the Locations and the Teams for those locations?

Previously, with SQL, I would have joined all the tables which would have given me a row for each, but I can’t seem to do it, even with a ViewModel combining them 🙁

public class Client
    {
        private System.Guid _id;

        [HiddenInput(DisplayValue = false)]
        public System.Guid ClientId {
            get
            {
                if (_id == null || _id == Guid.Empty)
                    _id = Guid.NewGuid();
                return _id;
            }
            set
            {
                _id = value;
            }
        }

        [Required(ErrorMessage = "The Client Name is required")]
        public String Name { get; set; }

        public virtual ICollection<Location> Locations { get; set; }
    }

public class Location
    {
        private System.Guid _id;

        [HiddenInput(DisplayValue = false)]
        public System.Guid LocationId {
            get
            {
                if (_id == null || _id == Guid.Empty)
                    _id = Guid.NewGuid();
                return _id;
            }
            set
            {
                _id = value;
            }
        }


        [Required(ErrorMessage = "The Site Name is Required")]
        public String Name { get; set; }

        [Required(ErrorMessage = "The Address is required")]
        public String Address { get; set; }

        [Required(ErrorMessage = "The Postcode is required")]
        public String Postcode { get; set; }

        public virtual ICollection<EngagementTeam> Teams { get; set; } 
    }

public class EngagementTeam
    {
        private System.Guid _id;

        [HiddenInput(DisplayValue = false)]
        public System.Guid EngagementTeamId {
            get
            {
                if (_id == null || _id == Guid.Empty)
                    _id = Guid.NewGuid();
                return _id;
            }
            set
            {
                _id = value;
            }
        }


        [Required(ErrorMessage = "The Team Name is required")]
        public String Name { get; set; }

        public virtual ICollection<Person> Members { get; set; }
    }
  • 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-05-27T11:31:25+00:00Added an answer on May 27, 2026 at 11:31 am

    I think you’re confusing your data or domain model with your UI or View Model. They are not typically the same thing.

    The reason is that View Models tend to be simpler, and only provide the data needed to display a particular view. This is important because view models get recreated by the model binder on every post back request, and if you ahve a very complex model then this makes it very hard for the model binder to create.

    You are also thinking about your model wrong. Client has no relationship to team whatsoever. This is not a “one to many to many”, this is two relationships, both 1 to many. Client is related to location. Location is related to team. Client is not related to Team, other than through location.

    So your client simply has a collection of Locations. And your Location has a collection of teams. Your Team will likely have a single reference to it’s location, and your location will have a single reference to it’s client. That’s it.

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

Sidebar

Related Questions

I have a model Client which has many :tours, association in it. I am
I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
Specifically, I have a model that has a field like this pub_date = models.DateField(date
My model is setup so Business has many clients, Client has one business. Inverse
I have a Client and ProposalRequest model that look like this: class Client <
Am using django forms on my app. I have a model Client like this:
If I have a model named Client and controller that looks like this class
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
Let's say I have a model like this class Foo(db.Model): id = db.StringProperty() bar
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content

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.