I have a table with 3 columns: ID, Name, ParentID.
How can I delete a specific record with all its children (n levels deep)?
Using Entity Framework 3.5.
I have a table with 3 columns: ID, Name, ParentID.
How can I delete a specific record with all its children (n levels deep)?
Using Entity Framework 3.5.
In SQL Set the database relationship to cascade delete and then rebuild your EDMX.
@Shivesh - I suggest you to use a little method implemented with recursion to delete a son, and all of its parents. Thus, if a parent have parents you can delete them also, and so on.
An alternative could be implementing a stored procedure, the corresponding link in EntityFramework, and pretty do the same.
Hope that helps,
That the table is self referencing is application logic, it is not expressed in the SQL definition, and therefore is not understood by EF.
To delete these records through EF you need to write a routine that starts at the top and loads all the sub items. Then mark all these items as deleted, then call save changes.
To delete an item:
context.DeleteObject(item);
context.SaveChanges();