PrepAway - Latest Free Exam Questions & Answers

What should you do?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application uses the ADO.NET Entity Framework to model entities.
The application includes a Customer entity along with a CustomerKey property of the Guid type as shown in the following exhibit:

You discover that when the application adds a new instance of a Customer, calling the SaveChanges method
results in the following error message: “Server generated keys are only supported for identity columns.”
You need to ensure that the application can add new Customer entities. What should you do?

PrepAway - Latest Free Exam Questions & Answers

A.
Add a handler for the ObjectContext.SavingChanges event.
In the event handler, set the CustomerKey value.

B.
Add a handler for the ObjectContext.ObjectMaterialized event.
In the event handler, set the CustomerKey value.

C.
Call the ObjectContext.Attach method before saving a Customer entity.

D.
Call the ObjectContext.CreateEntityKey method before saving a Customer entity.

Explanation:
SavingChanges() Event Occurs when changes are saved to the data source.
ObjectMaterialized() Event Occurs when a new entity object is created from data in the data source as part of a query or load operation.
Attach() Method Attaches an object or object graph to the object context when the object has an entity key.
CreateEntityKey() Creates the entity key for a specific object, or returns the entity key if it already exists.

ObjectContext Class
(http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx)


Leave a Reply