Entity Framework deletion issue
<p>I've got a simple application which has 2 tables (tblGrade and tblWidth). Grade can have multiple Widths. I set this up in sqlserver to have cascaded deletes and I also set cascade delete on the relationship in the edmx file. The foreign key is non nullable.</p>

<p>I've bound a datagridview to the Widths collection. This works fine, allowing me to add, view and delete the records however when I come to save the changes i get the following error.</p>

<blockquote>
  <p>System.InvalidOperationException: The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted.</p>
</blockquote>

<p>I've done some looking around and virtually everything points to me having to explicitly delete the Width entity. </p>

<ol>
<li>If the relationship is set to cascade deletes why do I have to explicitly delete this record?</li>
<li>Can i fix this without my form having to have a reference to the context. I was thinking of handling the SavingChanges event to remove the orphaned Width records but I'm not sure how to do that. (My app actually has a much more nested structure but I've cut it down for the example and I don't fancy passing the context to each of the controls or bubbling up delete events).</li>
</ol>

<p>Any ideas / things to look at would be most appreciated as I'm pretty new to EntityFramework. </p>

<pre><code>        Using ctxt As New ProductionDataEntities
            Dim grade = ctxt.Grades.First()
            Dim width = grade.GradeWidths(0)
            grade.GradeWidths.Remove(width)
            'ctxt.DeleteObject(width) **** will pass if this is uncommented.
            ctxt.SaveChanges()
        End Using
</code></pre>

<p><em>Details: EF5 - Db First, SqlServer 2012, vb.net 2010</em> </p>