title: Entity Framework the delete statement conflicted with the reference constraint
body: <p>I have two tables <code>Employee</code> (n) and <code>Store</code> (1), which have n:1 relationship.</p>
  
  <p><code>Employee</code> has foreign key <code>idStore</code> which is primary key from <code>Store</code>.</p>
  
  <p>Here is how I try to delete a row from <code>Employee</code>:</p>
  
  <pre><code>public void deleteEmployee(int idEmployee)
  {
     MyEntities pe = new MyEntities();
     try
     {
        var firstQuery = from e in pe.Employees
                         where e.idEmployee == idEmployee
                         select e;
        string findIdStore = firstQuery.First().StoreReference.EntityKey.EntityKeyValues[0].Value.ToString();
        int idStore = Int32.Parse(findIdStore);
        Store r = pe.Stores.First(c =&gt; c.idStore == idStore);
        r.Employees.Remove(firstQuery.First());
        pe.DeleteObject(firstQuery.First());
        pe.SaveChanges();
     }
     catch (Exception ex)
     {
        return;
     }
  }
  </code></pre>
  
  <p>And still, I get error that the delete statement conflicted with the reference constraint.</p>
  
  <p>The complete error is here:</p>
  
  <blockquote>
    <p>The DELETE statement conflicted with the REFERENCE constraint
    "FK_Bill_Employee". The conflict occurred in database
    "myDatabase", table "dbo.Bill", column 'idEmployeeMember'.<br>
    The statement has been terminated.</p>
  </blockquote>