PrepAway - Latest Free Exam Questions & Answers

What should you do?

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?

PrepAway - Latest Free Exam Questions & Answers

A.
In the database, remove the foreign key association between the Parts table and the Colors table, and then update the entity data model.

B.
Add a transation around the call to the SaveChanges() method and handle the exception by performing a retry.

C.
Add code before the call to the DeleteObject() method to examine the collection of Part objects associated with the Color object and then assign null to the Color property for each Part object.

D.
Change the End2 OnDelete proprety of the FK_PartColor association from None to Cascade

E.
Change the End1 OnDelete proprety of the FK_PartColor association from None to Cascade

One Comment on “What should you do?


Leave a Reply