Maybe it's better to change in sql.
You can use cascade delete instead.
Check out this article https://www.sqlshack.com/delete-cascade-and-update-cascade-in-sql-server-foreign-key/
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi All.
In WPF DataGrid I would like to delete a record. The DataGrid is populated by join of two tables Department and EmployeeDept. I create button to delete a record in the DataGrid. But records of source DataGrid are related to other EF related tables
This diagram displays related tables. For example, if in the EmployeeDept table need to be delete record DepartmentId=7 so in the EmployeeTask table should be deleted all records with related EmployeeDeptId number. If that is possible. How create LINQ or lambda to perform delete method? I will appreciate for detail explanation and sample.
Thanks.
Maybe it's better to change in sql.
You can use cascade delete instead.
Check out this article https://www.sqlshack.com/delete-cascade-and-update-cascade-in-sql-server-foreign-key/
Hi rmaurodev. Thanks for reply.
Actualy in project I'm using Entity Framework tables links to SQL Server database. I need to create LINQ or lambda query in method to delete records in multiple tables. If you know how to do it I will appreciate for help.
Thanks.
Trigger FOR DELETE ON EmpDep table where you delete the data from the task table ....
Sorry cannot test it right now
CREATE TRIGGER sampleTrigger
ON EmployeeDept
FOR DELETE
AS
DELETE FROM EmployeeTask
WHERE DepartmentId IN(SELECT deleted.id FROM deleted)
Hi,
Please refer to following posts if help:
https://stackoverflow.com/questions/29073597/linq-join-to-delete-contents-from-multiple-tables
https://www.c-sharpcorner.com/UploadFile/scottlysle/cascading-deletes-in-linq-to-sql/
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.