I have a table in SQL Server:
CREATE TABLE [dbo].[Account]
(
[AccountID] NVARCHAR (20) NOT NULL,
[ParentID] NVARCHAR (20) NULL
);
Also there is the same table FK ParentID-->AccountID ParentID is either null or contains the parent node.
In SQL Server the refrential integrity works correctly: It doesn't allow deleting the parent record if a child record exists. In my Entity Framework model which I created from the database when I try to delete the parent row EF first sets the child's ParentIDs to NULL and then deletes the parent row:
Account acc = new Account();
acc = (Account)accountListBox.SelectedItem;
_context.DeleteObject(acc);
_context.SaveChanges();
This 开发者_如何学运维is obviously not what I would have expected. Is there something wrong with my model? How can I enforce the ref. integrity in this case?
精彩评论