I have an object like below:
public class AdminMenuItem : BaseEntity
{
public int? ParentMenuItemId { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public AdminMenuItem ParentMenuItem { get; set; }
}
I added two menuitem. One is A that has not a parent menu. The other one B and A is the parent menu item for the B.
When I delete A, it throws me the exception on below:
The DELETE statement conflicted with the SAME TABLE REFERENCE constraint "FK_dbo.AdminMenuItem_dbo.AdminMenuItem_ParentMenuItemId".
The conflict occurred in database "A61DB", table "dbo.AdminMenuItem", column 'ParentMenuItemId'. The statement has been terminated
What configuration should I do to also delete child item while deleting parent ? Should I do it manually by putting it in a loop or is there a sufficient way to do it in entity framework 5 ? I try to use WillCascadeOnDelete but I couldnt success.
Also is there way to set child object foreign key to null ? (This is optional)