title: "Cannot remove an entity that has not been attached" error
body: <p>I have two tables: <code>Main</code> and <code>Vendors</code>.</p>
  
  <pre><code>Main table:
  MainID (PK)
  Name
  Address
  ...
  
  Vendors table:
  VendorID (PK)
  MainID (ForeignKey)
  Code
  ....
  </code></pre>
  
  <p>The data from the <code>Vendors</code> table is displayed into a <code>ListBox</code> control.</p>
  
  <p>When I try to delete a row from the <code>Vendors</code> table, using a button in the ListBox control, I get the following error:</p>
  
  <blockquote>
    <p><strong>Cannot remove an entity that has not been attached.</strong></p>
  </blockquote>
  
  <p>The Delete button code is:</p>
  
  <pre><code>        Dim button = TryCast(sender, Button)
      If button IsNot Nothing Then
          Using db As New theContext.theContext("Data Source=isostore:/theDB.sdf")
              Dim RecordToDelete As Vendors = TryCast(button.DataContext, Vendors)
  
              VendorsRecords.Remove(RecordToDelete)
  
              db.VendorsRecords.DeleteOnSubmit(RecordToDelete)
  
              db.SubmitChanges()
          End Using
      End If
  </code></pre>