You use Microsoft Visual Studio 2010 and the Microsoft .NET Framework 4.0 to create an application.
The application connects to a Microsoft SQL Server database. The application uses DataContexts to query the database.
You define a foreign key between the Customers and Orders tables in the database.
You need to ensure that when you delete a customer record, the corresponding order records are deleted.
You want to achieve this goal by using the minimum amount of development effort. What should you do?
A.
Override the Delete operation of the customer entity.
B.
Remove the foreign key between the Customers and Orders tables.
C.
Use the ExecuteDynamicDelete method of the DataContext object.
D.
Modify the foreign key between the Customers and Orders tables to enable the ON DELETE CASCADE option.
Explanation:
DataContext.ExecuteDynamicDelete Method
(http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.executedynamicdelete.aspx)
“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 have two options. The first option
is to set the ON DELETE CASCADE rule in the foreign-key constraint in the database. This
automatically deletes the child rows when a parent row is deleted. The other option is to write
your own code to first delete the child objects that would otherwise prevent the parent object
from being deleted.”
Training Kit 70-516