Linq to sql - delete some related records
I´m using linq to sql and I have a lot of tables with foreign keys lea开发者_StackOverflowding to the UserId.
Is it possible to have some of these foreign tables cleaned upon deletion.
For example I want the users profile (other table) to be deleted automatically with the user but not the users forum posts.
Is this possible or do I have to handle this with code?
I think this link is very usefull.
LINQ to SQL does not support or recognize cascade-delete operations. If you want to delete a row in a table that has constraints against it, you must complete either of the following tasks:
Set the ON DELETE CASCADE rule in the foreign-key constraint in the
database.Use your own code to first delete the child objects that prevent the parent object from being deleted.
I am not sure with code, but couldn't you set the Cascade on Delete option in SQL?
精彩评论