title: Two foreign keys to one Entity Framework Core table
body: <p>I am developing language dictionary with asp core 2.0. I wonder how to 
   properly design my database. I came across similar question: <a href="https://stackoverflow.com/questions/16914185/how-to-design-a-database-for-%20translation-dictionary">How to design a database for translation dictionary?</a>.</p>
  
  <p>I decided to create a database like in the following picture:</p>
  
  <p><a href="https://i.stack.imgur.com/GWmgl.png" rel="nofollow noreferrer">database structure that i wanna realize in ef core</a></p>
  
  <p>But i do not know how to realize this structure with entity framework core 2.0.</p>
  
  <p>Word entity</p>
  
  <pre><code>    public class Word
      {
        public Word()
          {
            Translations = new HashSet&lt;Translation&gt;();
          }
        [Key]
        public Guid WordId { get; set; }
        [Required]
        public Guid LangCodeId { get; set; }
  
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", 
          "CA2227:CollectionPropertiesShouldBeReadOnly")]
         public virtual ICollection&lt;Translation&gt; Translations { get; set; }
  
  
  }
  </code></pre>
  
  <p>Translation entity </p>
  
  <pre><code>   public class Translation
  {
      [Key]
      public Guid TranslationId { get; set; }
      public Guid WordId1 { get; set; }
      public Guid WordId2 { get; set; }
  
      //[ForeignKey("WordId1,WordId2")]
      public Word Words { get; set; }
  
  }
  </code></pre>
  
  <p>fluent API</p>
  
  <pre><code>  modelBuilder.Entity&lt;Translation&gt;()
              .HasOne(w =&gt; w.Words)
              .WithMany(m =&gt; m.Translations)
              .HasForeignKey(fk =&gt; new { fk.WordId1, fk.WordId2 });
  </code></pre>
  
  <p>when i try to add a migration, i get the error:</p>
  
  <pre><code>   The relationship from 'Translation.Words' to 'Word.Translations' with 
     foreign key properties {'WordId1' : Guid, 'WordId2' : Guid} cannot target 
     the primary key {'WordId' : Guid} because it is not compatible. Configure 
     a principal key or a set of compatible foreign key properties for this 
     relationship.
  </code></pre>