title: Entity Framework Core - Related products of type product
body: <p>I'm using Entity Framework Core and Fluent API.</p>
  
  <p>I'm trying to implement a relatedProducts array that is included in my product model like so:</p>
  
  <pre><code>{
      "id": 13
      "name": "something",
      "heading": "something else",
      "summary": "please put me out my misery!"
      "relatedProducts": [
          {
              "name": "something related",
              "heading": "something else related",
              "summary": "something in summary"
          },
          {
              "name": "something related",
              "heading": "something else related",
              "summary": "something in summary"
          }
      ]
  }
  </code></pre>
  
  <p>I currently have this in my Context:</p>
  
  <pre><code>        modelBuilder.Entity&lt;RelatedProduct&gt;()
              .HasKey(r =&gt; new { r.ProductId, r.RelatedId });
  
          modelBuilder.Entity&lt;RelatedProduct&gt;()
              .HasOne(p =&gt; p.Product)
              .WithMany(r =&gt; r.RelatedProducts)
              .HasForeignKey(p =&gt; p.ProductId)
              .OnDelete(DeleteBehavior.Restrict);
  
          modelBuilder.Entity&lt;RelatedProduct&gt;()
              .HasOne(p =&gt; p.Related)
              .WithMany(r =&gt; r.ProductsRelated)
              .HasForeignKey(p =&gt; p.RelatedId)
              .OnDelete(DeleteBehavior.Restrict);
  </code></pre>
  
  <p>My Related Product class looks like this:</p>
  
  <pre><code>public class RelatedProduct
  {
      public int ProductId { get; set; }
      public virtual Product Product { get; set; }
  
      public int RelatedId { get; set; }
      public virtual Product Related { get; set; }
  }
  </code></pre>
  
  <p>The trouble is my relatedProduct array is just coming back empty even though I've linked up the Ids in the db.</p>
  
  <p>Any assistance on this would be awesome as i don't want to end up 'Bodging' it!</p>