Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting an extra foreign key column with Entity Framework Code First Foreign Key Attributes?
    primarykey
    data
    text
    <p>I recently came across this strange problem with Entity Framework Code First.</p> <p>My class looks like this</p> <pre><code>public class Status { [Key] public int StatusID { get; set; } public string Name { get; set; } public int MemberID { get; set; } [ForeignKey("MemberID")] public virtual Member Member { get; set; } public int PosterID { get; set; } [ForeignKey("PosterID")] public virtual Member Poster { get; set; } public virtual ICollection&lt;StatusLike&gt; StatusLikes { get; set; } public virtual ICollection&lt;StatusComment&gt; StatusComments { get; set; } } </code></pre> <p>My Member class looks like this</p> <pre><code> public class Member { [Key] public int MemberID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Bio { get; set; } public virtual ICollection&lt;MemberCourseTaken&gt; MemberCourseTakens { get; set; } public virtual ICollection&lt;Status&gt; Statuses { get; set; } public virtual ICollection&lt;Club&gt; FoundedClubs { get; set; } public string EmailAddress { get; set; } public string Password { get; set; } public string Phone { get; set; } public int AccountSourceID { get; set; } public AccountSource AccountSource { get; set; } public int AddressID { get; set; } public Address Address { get; set; } public string ProfilePhoto { get; set; } public int MemberRankID { get; set; } public MemberRank MemberRank { get; set; } public DateTime Created { get; set; } public DateTime Modified { get; set; } } </code></pre> <p>And for whatever reason the database table that is created has the following columns</p> <pre><code>StatusID Name MemberID PosterID Member_MemberID </code></pre> <p>with <code>MemberID</code>, <code>PosterID</code>, and <code>Member_MemberID</code> being foreign keys.</p> <p>How can I keep <code>Member_MemberID</code> from being generated?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload