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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:13:22+00:00 2026-05-28T17:13:22+00:00

I am creating a class library for a project management application. I will brief

  • 0

I am creating a class library for a project management application. I will brief you on how all the entities are setup to aid in question.

A user subscribes to a plan during registration. Every plan contains modules/applications he can use after successful verification of his account. Project, Company and Plans are the modules for which i am creating the class library and these are the modules that exist at every stage of the user life cycle. Roles determine what the user can perform or not. Each company(only one for a user) can house many projects and each project have dedicated Project Lead with his resources. Project Lead is another user with higher privileges/Roles. Now here is the confusing part because both seems fine to me:Which of the class hierarchy i should follow 1 or 2

1

User

  - Subscriptions ( List<> )

  - Projects ( List<> )
      - Client ( Client )
      - ProjectLead( User )
      - Resources(List<>)

2

Application

   - Projects ( List<> )

     - Client ( Client )
     - ProjectLead ( User )
     - Resources ( List<> )

User

  - GetProjects ( List <Project> )

Confusion barely comes to this point, the client is associated with project through foreign key ProjectId. So while creating a class for Client ,

to denote which project the client belongs should i create a Project
Class
inside Client class or Should client be housed inside the
Project Class.

  • 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-28T17:13:23+00:00Added an answer on May 28, 2026 at 5:13 pm

    Do I understand correctly that you are confused which object should have a relation with another object, like this:

    option 1: a user HAS projects (where he is the LEAD)
    option 2: a project HAS a user (which is the lead)

    And more of that.

    The good news is: you don’t have to choose. You can write a bidirectional relationship.
    There are several ways to implement this.

    Because you talk about foreign keys, am I right in assuming you are using a backend database to persist the objects? In that case, you can use an Object-Relational database Mapper (ORM) like Entity Framework. If not, you’ll have to do some work yourself, which is something I’d personally avoid 😉

    Entity framework

    You just write your database with all relationships first and then let entity framework generate the corresponding classes for you. All these classes have bidirectional relationships.

    Example:

    You have two tables:

    • Users
      • id: int
      • Name: nvarchar(50)
    • Projects
      • id: int
      • LeadUserId: int FOREIGN KEY to Users.id
      • Name: nvarchar(50)

    Entity framework will translate this into two classes like this

    • User

      • id: int
      • Name: string
      • Projects: List
    • Project

      • id: int
      • Name: string
      • User: User

    When you now for example set the ‘User’ field of a Project object to a different user, the project is automatically removed from the Projects list of the original user, and is added to the new user’s Projects list.

    You can persist changes to the database by calling a .SaveChanges() method on the database context object.

    Write your own bi-directional association

    The main problem with bi-directional relations is that you have to maintain consistency. With simple one-to-one relationships it’s not that bad, but with one-to-many relationships (as is the case here, one user to many projects) it’s a bit more difficult.

    Below you find an implementation that uses the rather excellent ObservableCollection class.

    The Project class

    public class Project {
        public string Name { get; set; }
    
        private User _leadUser;
        public User LeadUser {
            get { return _leadUser; }
            set {
                if (_leadUser != value) {
                    if (_leadUser != null) {
                        _leadUser.Projects.Remove(this);
                        if (!value.Projects.Contains(this)) {
                            value.Projects.Add(this);
                        }
                    }
                    _leadUser = value;
                }
            }
        }
    }
    

    The User class

    public class User {
    
        public string Name { get; set; }
    
        private ObservableCollection<Project> _projects = new ObservableCollection<Project>();
        public ObservableCollection<Project> Projects { get { return _projects; } }
    
        public User() {
            Projects.CollectionChanged += OnProjectCollectionChanged;
        }
    
        protected void OnProjectCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) {
            var projects = sender as IEnumerable<Project>;
            switch (e.Action) {
                case NotifyCollectionChangedAction.Add:
                    foreach (var project in projects) {
                        if (project.LeadUser != this) {
                            project.LeadUser = this;
                        }
                    }
                    break;
                case NotifyCollectionChangedAction.Move:
                    break;
                case NotifyCollectionChangedAction.Remove:
                    foreach (var project in projects) {
                        if (project.LeadUser == this) {
                            project.LeadUser = null;
                        }
                    }
                    break;
                case NotifyCollectionChangedAction.Replace:
                    break;
                case NotifyCollectionChangedAction.Reset:
                    break;
                default:
                    break;
            }
        }
    }
    

    Hopefully this post was useful to you.

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

Sidebar

Related Questions

This seems confusing to me - im creating a class library, and adding all
I am creating one class library project. Now by default I have one App.Config
When creating a class library in C++, you can choose between dynamic ( .dll
Coming from a corporate IT environment, the standard was always creating a class library
I am creating a decoupled WMI provider in a class library. Everything I have
I am creating a class for an application backbone and I need this function
I have created a RIA services class library project and things are not going
I'm creating a class library that makes available some XAML windows (in theory). To
I'm debbuging a web application that has a WebSite and a class library containg
I have a library project which contains an abstract class, let's say ClassA .

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.