70-516 · Question #70
You have a ContosoEntities context object named context and a Color object stored in a variable named color. You write the following code: context.Colors.DeleteObject(color); context.SaveChanges()…
The correct answer is C. Add code before the call to the DeleteObject() method to examine the collection of Part. See the full explanation below for the reasoning.
Question
You have a ContosoEntities context object named context and a Color object stored in a variable named color. You write the following code:
context.Colors.DeleteObject(color); context.SaveChanges(); When the code runs, it generates the following exception:
System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for detials. ---> System.Data.SqlClient.SqlException: The DELETE satement conflicted with the REFERENCE constraint "FK_PartColor". The conflict occurred in database "Contoso", table "dbo.Parts", column 'ColorId' You need to resolve the exception without negatively impacting the rest of the application. What should you do?
Options
- AIn the database, remove the foreign key association between the Parts table and the Colors
- BAdd a transation around the call to the SaveChanges() method and handle the exception by
- CAdd code before the call to the DeleteObject() method to examine the collection of Part
- DChange the End2 OnDelete proprety of the FK_PartColor association from None to Cascade
- EChange the End1 OnDelete proprety of the FK_PartColor association from None to Cascade
How the community answered
(33 responses)- A3% (1)
- B6% (2)
- C82% (27)
- D9% (3)
Community Discussion
No community discussion yet for this question.