PrepAway - Latest Free Exam Questions & Answers

How can you remedy the problem?

DRAG DROP
Exhibit: Server generated keys are only supported for identity columns
There is MS Visual Studio 2010 and MS .NET Framework 4 application PassGuideApp.
To access employee data from PassGuideDB ADO.NET Entity Framework is used to model
entities.
PassGuideApp includes an Employees entity.
The Employees entity include a EmployeeKey, a primary key field, with type Guid.
However, there is a problem when PassGuideApp uses the Save Changes method to save a
new instance of Employee entity.
How can you remedy the problem?

PrepAway - Latest Free Exam Questions & Answers

Answer:

Explanation:

One Comment on “How can you remedy the problem?

  1. John Galt says:

    So basically the question wants you to fix a problem that happens when you try to save an entity. The problem happens because server generated keys are not supported, so you need to generate the key yourself. The best time to do that is during saving, which is why you need to hook up to the SavingChanges event, and generate the key inside the handler for the said event.

    http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.savingchanges%28v=vs.110%29.aspx

    The SavingChanges event is raised at the start of a SaveChanges operation on an ObjectContext. This event is typically used to validate changed objects before new values are written to the database.




    0



    0

Leave a Reply