Reputation:
I am trying to save a foreign key in 2 columns of a row. For some reason, this is acting wonky because some of the navigation properties are showing up as columns in my table... Here is the model. What am I doing wrong?
public class BorrowedPerson
{
public int BorrowedPersonID { get; set; }
public Nullable<int> PersonID { get; set; }
public Nullable<int> CompanyID { get; set; }
public Nullable<int> TempCompanyID { get; set; }
public virtual Person Person { get; set; }
public virtual Company Company { get; set; }
public virtual Company TempCompanyID { get; set; }
}
Upvotes: 0
Views: 39
Reputation:
I figured it out... Very simple answer. When you are specifying more than one navigation property to the same type, it requires you to manually specify the foreign key like so.
public class BorrowedPerson
{
public int BorrowedPersonID { get; set; }
public Nullable<int> PersonID { get; set; }
public Nullable<int> CompanyID { get; set; }
public Nullable<int> TempCompanyID { get; set; }
public virtual Person Person { get; set; }
[ForeignKey("CompanyID ")]
public virtual Company Company { get; set; }
[ForeignKey("TempCompanyID")]
public virtual Company TempCompanyID { get; set; }
}
Upvotes: 1