Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving Entities from Database table via Navigation Property using RIA Services and Entity Framework
    text
    copied!<p>I have 3 normalised tables consisting of Employees, Departments and EmployeesToDepartments. I wish to be able to assign an Employee to one or more Department, hence the link table (EmployeesToDepartments). I can successfully query the database and extract the full hierarchy of entities via the Navigation properties using</p> <pre><code>this.ObjectContext.Employees.Include("EmployeesToDepartments").Include("EmployeesToDepartments.Department") </code></pre> <p>plus the [Include] attribute in the metadata, thus allowing me to access the Departments for a given Employee. Upon trying to remove a link between an [Employee] and [Department] in the [EmployeesToDepartments] table I was given a Foreign Key Constrain error.</p> <p>I have simplified my model to include just one navigation property between [Employees] and [EmployeesToDepartments]. A Foreign Key constraint between[Employees].[ID] and [EmployeesToDepartments].[IDEmployee] was preventing me from updating the EmployeesToDepartments table. With this removed via a Relationship setting I can now update the table. I can now execute the following code</p> <pre><code>foreach (var rel in _employee.EmployeesToDepartments) { _employee.EmployeesToDepartments.Remove(rel); } _domainContext.SubmitChanges(); </code></pre> <p>without error.</p> <p>I was expecting to see the entries in the RelEmployeesToDepartments with the IDEmployee to have been deleted. What I see in the table are the value 0 where the IDEmployee previously was.</p> <p>Is it possible to force a DELETE statement to be issued? Am I misunderstanding the basic concepts here?</p> <p>Any help would be much appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload