PrepAway - Latest Free Exam Questions & Answers

What should you do?

You have an existing ContosoEntities context object named context.
Calling the SaveChanges() method on the context object generates an exception that has the following inner exception:

System.Data.SqlClient.SqlException: Cannot insert duplicate key row in object ‘dbo.Colors’ with unique index ‘IX_Colors’.

You need to ensure that a call to SaveChanges() on the context object does not generate this exception. What should you do?

PrepAway - Latest Free Exam Questions & Answers

A.
Examine the code to see how Color objects are allocated.
Replace any instance of the new Color() method with a call to the ContosoEntities.LoadOrCreate() method.

B.
Add a try/catch statement around every call to the SaveChanges() method.

C.
Remove the unique constraint on the Name column in the Colors table.

D.
Override the SaveChanges() method on the ContosoEntities class,
call the ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Added) method,
and call the AcceptChanges() method on each ObjectStateEntry object it returns

2 Comments on “What should you do?


Leave a Reply