title: Entity Framework code first duplicating the foreign key
body: <p>I'm getting duplicated foreign key in one of my tables. I'm using EF code first and mapping the tables with Fluent API. I have no idea why this is happening.</p>
  
  <p>Class that represents the table:</p>
  
  <pre><code>public class ColunaSugestUsuario 
  {
      [Key]
      public int CODCOLSUGEST { get; set; }
      public ColunaSugest COLSUGEST { get; set; }
      public Usuarios USUARIO { get; set; }
      public Sugestoes SUGESTOES { get; set; }
      public int CODINDEX { get; set; }
  }
  </code></pre>
  
  <p>Note: Every custom class in this code contains an <code>ICollection</code> of <code>ColunaSugestUsuario</code> named <code>COLUNASUGESTUSUARIO</code>.</p>
  
  <p>Fluent API:</p>
  
  <pre><code>modelBuilder.Entity&lt;ColunaSugestUsuario&gt;()
      .HasRequired(s =&gt; s.COLSUGEST)
      .WithMany(s =&gt; s.COLUNASUGESTUSUARIO)
      .Map(x =&gt; x.MapKey("CODSUGEST"));
  modelBuilder.Entity&lt;ColunaSugestUsuario&gt;()
      .HasRequired(s =&gt; s.USUARIO)
      .WithMany(s =&gt; s.COLUNASUGESTUSUARIO)
      .Map(x =&gt; x.MapKey("CODCOLUNA"));
  modelBuilder.Entity&lt;ColunaSugestUsuario&gt;()
      .HasRequired(s =&gt; s.SUGESTOES)
      .WithMany(s =&gt; s.COLUNASUGESTUSUARIO)
      .Map(x =&gt; x.MapKey("CODUSUARIO"));
  </code></pre>
  
  <p>Result:</p>
  
  <p><a href="https://i.stack.imgur.com/ppPOm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ppPOm.png" alt="enter image description here"></a></p>
  
  <p>This <em>ColunaSugest_CODCOLUNA</em> should not be there. Right?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I've already tried a fully defined relationship at both ends as well (the foreign key as a class attribute), but nothing happened</p>