title: Entity Framework with two separate DBContext
body: <p>I am using Entity Framework 4, and I am getting this error:</p>
  
  <blockquote>
    <p>A foreign key value cannot be inserted because a corresponding primary
    key value does not exist. [ Foreign key constraint name =
    FK_Table1_Table2_ColumnId ]</p>
  </blockquote>
  
  <p>Where <code>Table1</code> is in one <code>DBContext</code>:</p>
  
  <pre><code>public class Database1DB : DbContext
  {
     public DbSet&lt;Table1&gt; TableOne { get; set; }
  }
  </code></pre>
  
  <p>and <code>Table 2</code> is in another <code>DBContext</code>:</p>
  
  <pre><code>public class Database2DB : DbContext
  {
     public DbSet&lt;Table2&gt; TabeTwo {get;set;}
  }
  </code></pre>
  
  <p><code>Table 1</code> has a foreign key reference to <code>Table2</code>'s column like this:</p>
  
  <pre><code>public class Table1
  {
     [Key]
     public int Id {get;set;}
  
     [ForeignKey("Table2")
     public int ColumnId {get;set;}
  
     public virtual Table2 Table2 {get;set;}
  }
  
  public class Table2
  {
     [Key]
     public int Id {get;set;}
  }
  </code></pre>