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

  • Home
  • SEARCH
  • 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 8585193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:59:54+00:00 2026-06-11T21:59:54+00:00

I have a set of four POCO objects that need to reference themselves in

  • 0

I have a set of four POCO objects that need to reference themselves in this way:

A Freelancer can have multiple Clients

Clients can have multiple Projects

Projects can have multiple Stories.

One this I want to make sure is possible is that a freelancer starts off with no clients, and client starts off with no projects, and a project starts off with no stories, so I guess they need to be nullable?

The opposite is true the other direction, a story NEEDS a project, project needs a client, and a client needs a freelancer.

I just want to see if there is anything that I need to do when I am creating the model (onModelCreating override) to make sure this is the relationship that happens.

Here are my objects:

public class Freelancer
{
    public int ID { get; set; }
    public string Email { get; set; }
    public string Password { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string CompanyName { get; set; }
    public string Avatar { get; set; }
    public Address FreelancerAddress { get; set; }
    public ICollection<Client> Clients { get; set; }
}


public class Client
{
    public int ID { get; set; }
    public string Name { get; set; }
    public Address ClientAddress { get; set; }
    public string Logo { get; set; }
    public ICollection<Project> Projects { get; set; }
}


public class Project
{
    public int ID { get; set; }
    public string Name { get; set; }
    public string Summary { get; set; }
    public string Description { get; set; }
    public ICollection<Story> Stories { get; set; }
}


 public class Story
{
    public int ID { get; set; }
    public string Title { get; set; }
    public DateTime Start { get; set; }
    public DateTime End { get; set; }
    public decimal Duration { get; set; }
    public bool Billable { get; set; }
    public string Notes { get; set; }
}

I understand EF does some things automatically, I am just asking if there is more I need to do to make sure I have the relationship I want. Thanks

  • 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-11T21:59:55+00:00Added an answer on June 11, 2026 at 9:59 pm

    By convention your model will create optional relationships (“client can have a freelancer but doesn’t need to”) but since you want required relationships (“client needs a freelancer”) you must define it with Fluent API:

    modelBuilder.Entity<Freelancer>()
        .HasMany(f => f.Clients)
        .WithRequired()
        .Map(m => m.MapKey("FreelancerID"));  // FK column name in Clients table
    

    You can work without the last line (Map). EF will then create a default foreign key name, something with underscore, maybe Freelancer_ID.

    And the same mapping for the other relationships.

    Alternatively you can introduce inverse navigation properties with foreign key properties:

    public class Client
    {
        public int ID { get; set; }
        //...
        public ICollection<Project> Projects { get; set; }
    
        public int FreelancerID { get; set; }
        public Freelancer Freelancer { get; set; }
    }
    

    With such a model EF will recognize the relationships as required automatically because the foreign key property FreelancerID is not nullable and you don’t need additional mapping with Fluent API.

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

Sidebar

Related Questions

I have a set of four ASP.NET roles that I have been trying to
I have a set of four images, and my functionality goal is so that
I have an app with four activities. I have set the intent-filter on one
i have four radio buttons , and i want to set a text for
I have set the eclipse java formatter to wrap lines that exceed 120 characters
I have set up an app that is registered for remote notifications. - (void)application:(UIApplication*)application
I have set the size of the tableView that I show as the popoverController
So i have a set of four points in 3D Space. P1 [0, 0,
I have set my app to update four xml feeds in the background (if
I have a set of functions that are templated both by an integer type

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.