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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:11:15+00:00 2026-05-23T04:11:15+00:00

i’m with a trouble; For initial imagine that we have an entity Member, and

  • 0

i’m with a trouble;

For initial imagine that we have an entity Member, and Member has Projects..

If you ask: Do projects have members? Yes they have…

Members (N*) <-> Project (N*) – so is a n-n-relationship.

But in my domain application i wanna say too that one Member is responsible for N projects, and one Project has one Member..

 public class Member : User
{
    public virtual ICollection<Project> ProjectsResponsable { get; set; }
    public virtual ICollection<Project> ProjectsWorker { get; set; }
}
public class Project
{
    public virtual int ProjectID { get; set; }
    public virtual String Name { get; set; }
    public virtual bool Enabled { get; set; }
    public virtual DateTime CreatedDate { get; set; }
    public virtual String Description { get; set; }

    public virtual Member Responsable { get; set; }
    public virtual ICollection<Member> Workers { get; set; }
    public virtual ICollection<Issue> Issues { get; set; }
}

For ProjectsWorker property in Worker will be a N-N relationship between Member and Project, but with this (the EF framework only creates for me the 1-way relashionship)

My question is… who can i a map these two relationships with code-first.
I was using DatabaseFirst, and now with code-first it appears to be very powerful but restrict me a little now.

  • 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-23T04:11:15+00:00Added an answer on May 23, 2026 at 4:11 am

    You must tell EF which relationships belong together. You can do this either with data annotations …

    public class Member : User
    {
        [InverseProperty("Responsable")]
        public virtual ICollection<Project> ProjectsResponsable { get; set; }
        [InverseProperty("Workers")]
        public virtual ICollection<Project> ProjectsWorker { get; set; }
    }
    
    public class Project
    {
        public virtual int ProjectID { get; set; }
        // ...
        [InverseProperty("ProjectsResponsable")]
        public virtual Member Responsable { get; set; }
        [InverseProperty("ProjectsWorker")]
        public virtual ICollection<Member> Workers { get; set; }
        // ...
    }
    

    (I believe the InverseProperty attribute is only necessary on one side of the relationship, but I am not sure.)

    … or in Fluent API:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Member>()
            .HasMany(m => m.ProjectsResponsable)
            .WithOptional(p => p.Responsable)  // or WithRequired(...)
            .WillCascadeOnDelete(false);
    
        modelBuilder.Entity<Member>()
            .HasMany(m => m.ProjectsWorker)
            .WithMany(p => p.Workers)
            .Map(a => {
                a.ToTable("MemberProjects");
                a.MapLeftKey("MemberID");
                a.MapRightKey("ProjectID");
            });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.