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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:32:55+00:00 2026-05-25T20:32:55+00:00

Popular example: In the issue tracker JIRA, issues can be linked to other issues.

  • 0

Popular example: In the issue tracker JIRA, issues can be linked to other issues. The link itself has some data attached, in particular a type.

Example:

Issue A -> depends on -> Issue B
Issue B <- is depended on by <- Issue A

We are introducing the same kind of relationship for an entity in our C# ASP.NET MVC application using EF 4.1 CodeFirst, and I’m wondering how to best model this relationship?


Details:

There are some particularities about this situation:

  • A link has some data attached, so we can’t simply model a many-to-many relationship between issues and issues. We rather have to introduce a new entity Link, which represents a relationship between two issues.
  • A link, by definition, links two instances of the same entity, it is a “two-to-many” relationship (a link has two issues, an issue can have many links).
  • The link is directed, which means, if Issue A depends on Issue B, then Issue B is depended on by Issue A.

We will certainly have a Link entity that looks like this:

public class Link
{
    public int ID { get; set; }
    public Issue IssueA { get; set; }
    public Issue IssueB { get; set; }
    public LinkType Type { get; set; }
}

The Issue class might look like this:

public class Issue
{
    public int ID { get; set; }
    public virtual ICollection<Link> Links { get; set; }
}

Currently there would be only one link type: dependency. So, the link type would look like this:

public class LinkType
{
    public int ID { get; set; }
    public string ForwardName { get; set; } // depends on
    public string BackwardName { get; set; } // is depended on by
}

Now for the big question:

If I want EF to automatically manage Issue.Links, I have to tell it what Foreign key on the Link table to use. Either I use IssueA, or I use IssueB. I can’t use both, can I?

Either I define:

modelBuilder.Entity<Issue>().HasMany(i => i.Links).WithRequired(l => l.IssueA);

or I define:

modelBuilder.Entity<Issue>().HasMany(i => i.Links).WithRequired(l => l.IssueB);

Possible approaches – I am curious about your feedback on whether some of them will lead to troubles, cannot be implemented, or whether any of these approaches can be regarded as “best practice”:

  • Add two Collections to the Issue, ICollection<Link> OutgoingLinks, ICollection<Link> IncomingLinks. This way the collections can be maintained by EF, but from a business logic point of view they don’t make much sense.
  • Only add one collection and configure EF 4.1 to add incoming and outgoing links to it, if that is possible.
  • Only add one collection and implement it on my own:

    ICollection<Link> AllLinks { return _context.Links.Where(l => l.IssueA == this || l.IssueB == this).ToList(); }

    The problem with this approach is that the domain entity executes data access tasks which is bad in terms of seperation of concerns.

  • Any other?

  • 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-25T20:32:56+00:00Added an answer on May 25, 2026 at 8:32 pm

    Option (1) is the way to go in my opinion, together with a readonly helper perhaps which combines the two collections:

    public class Issue
    {
        public int ID { get; set; }
        public virtual ICollection<Link> OutgoingLinks { get; set; }
        public virtual ICollection<Link> InComingLinks { get; set; }
    
        public IEnumerable<Link> Links // not mapped because readonly
        {
            get { return OutgoingLinks.Concat(InComingLinks); }
        }
    }
    

    Option (2) isn’t possible because you cannot map one navigation property to two different ends/navigation properties.

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

Sidebar

Related Questions

I know this is a popular topic and I've read some other articles on
Assume that the array has integers between 1 and 1,000,000. I know some popular
Microsoft like implementing their own versions of popular open-source frameworks and assemblies, for example:
It seems Scrum and Agile tests/assertions are becoming popular this year. For example, Nokia
I want to make an app which (amongst other things) can parse feeds loaded
For example, consider the following code (in a model): scope :popular, where(views >= 250
How are the magazines apps built? For example Popular Science , Auto Trends and
I know this may seem like a silly and tiny issue, but I can't
For example, I have a data frame with data across categories and subcategories and
Allen Holub wrote the following, You can't have a program without some coupling. Nonetheless,

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.