title: The INSERT statement conflicted with the FOREIGN KEY constraint - Entity Framework
body: <p>I'm having issues with a relationship between 2 entities;</p>
  
  <p>My classes are as follows;</p>
  
  <pre><code>public class Cis 
  {
       [Key]
       public int CisId { get; set; }
       public int ProjectId { get; set; }
  
       [ForeignKey("ProjectId")] 
       public virtual ICollection&lt;Overhead&gt; Overheads { get; set; }
  
  }   
  
  public class Overhead 
  {
      public int Id { get; set; }     
      public int ProjectId { get; set; }
      public SecuredWorkType SecuredWorkType { get; set; }
      public decimal? OverheadRecoveryTotalValue { get; set; }
      public decimal? BudgetedFinancialResultValue { get; set; }
      public decimal? SecuredValue { get; set; }
      public decimal? OverheadRecoveryTotalPercentage { get; set; }
  }
  </code></pre>
  
  <p>When I attempt to save a CIS object with multiple overheads on it, I get the following error</p>
  
  <pre><code>The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.Overhead_dbo.Cis_ProjectId". The conflict occurred in database "CisLatest", table "dbo.Cis", column 'CisId'.The statement has been terminated."
  </code></pre>
  
  <p>I cannot use the CisId on the Cis as my foreign key because of design concerns - when I was using the CisId as the foreign key it worked fine.</p>
  
  <p>I have seen similar questions and answers on here, though they show putting the parent entity inside the child? Not sure if this applies in this case</p>
  
  <p>Thanks for your help. </p>