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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:44:26+00:00 2026-05-28T02:44:26+00:00

I have Person and Course Entities With multiple relationships: public class Course { public

  • 0

I have Person and Course Entities With multiple relationships:

public class Course
{
    public int CourseID { get; set; }
    public virtual Person Leader { get; set; }
    public virtual ICollection<Person> Teachers { get; set; }
    public virtual Person CreatedBy { get; set; }
    public virtual Person UpdatedBy { get; set; }
    ...
}

public class Person
{
    public int PersonID { get; set; }
    public virtual ICollection<Course> CoursesCreated { get; set; }
    public virtual ICollection<Course> CoursesUpdated { get; set; }
    public virtual ICollection<Course> CoursesLead { get; set; }
    public virtual ICollection<Course> CoursesTutored { get; set; }
    ...
}

I have the following mapping:

modelBuilder.Entity<Course>().HasMany(x => x.Tutors)
                           .WithMany(p => p.CoursesTutored)
                           .Map(x =>
                               {
                                   x.MapLeftKey("PersonID");
                                   x.MapRightKey("CourseID");
                                   x.ToTable("Course_Tutors");
                               });

This works in that it sets up the Course_Tutors table as well as providing the course table with Leader_PersonID, CreatedBy_PersonID and UpdatedBy_PersonID.

However it also creates three extra Person columns in the course table: Person_PersonID1, Person_PersonID2, Person_PersonID3.

Can someone tell me how to get rid of these? I am assuming my mapping needs some more work.

  • 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-28T02:44:26+00:00Added an answer on May 28, 2026 at 2:44 am

    Code First has problems identifying relationships by conversions when you have more than one relationship between two entities. You need to explicitly configure them.

    modelBuilder.Entity<Course>()
         .HasRequired(c => c.Leader)
         .WithMany(p => p.CoursesLead)
         .Map(m => m.MapKey("Leader_PersonID"));
    
    modelBuilder.Entity<Course>()
         .HasRequired(c => c.CreatedBy)
         .WithMany(p => p.CoursesCreated)
         .Map(m => m.MapKey("CreatedBy_PersonID"));
    
    modelBuilder.Entity<Course>()
         .HasRequired(c => c.UpdatedBy)
         .WithMany(p => p.CoursesUpdated)
         .Map(m => m.MapKey("UpdatedBy_PersonID"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a class, e.g.: public class Person { public virtual int Id
I have a simple class as defined below: public class Person { int _id;
I have the following class and extension class (for this example): public class Person<T>
I have created a class Person that looks like this: public class Person {
I have a Person object with two constructors - one takes an int (personId),
I have a Person Class and based on some help I received in this
I have a Person class. A Person can have an associated control. Can I
I have a Person class. A person class contains a collection of Friends (also
I have a person class, then have a family class where I have a
I have a class Person which can have several Homes, each one with one

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.