Which line of code should you use?

You develop a Microsoft .NET application that uses Entity Framework to store entities in a Microsft SQL Server 2008 database.
While the application is disconnected from the database, entities that are modified, are serialized to a local file.

The next time the application connects to the database, it retrieves the identity from the database by using an object context
named context and stores the entity in a variable named remoteCustomer.
The application then serializes the Customer entity from the local file and stores the entity in a variable named localCustomer.
The remoteCustomer and the localCustomer variables have the same entity key.

You need to ensure that the offline changes to the Customer entity is persisted in the database when the ObjectContext.SaveChanges() method is called.
Which line of code should you use?

You develop a Microsoft .NET application that uses Entity Framework to store entities in a Microsft SQL Server 2008 database.
While the application is disconnected from the database, entities that are modified, are serialized to a local file.

The next time the application connects to the database, it retrieves the identity from the database by using an object context
named context and stores the entity in a variable named remoteCustomer.
The application then serializes the Customer entity from the local file and stores the entity in a variable named localCustomer.
The remoteCustomer and the localCustomer variables have the same entity key.

You need to ensure that the offline changes to the Customer entity is persisted in the database when the ObjectContext.SaveChanges() method is called.
Which line of code should you use?

A.
context.ApplyOriginalValues(“Customers”, remoteCustomer);

B.
context.ApplyOriginalValues(“Customers”, localCustomer);

C.
context.ApplyCurrentValues(“Customers”, remoteCustomer);

D.
context.ApplyCurrentValues(“Customers”, localCustomer);

Explanation:
http://msdn.microsoft.com/en-us/library/dd487246.aspx



Leave a Reply 1

Your email address will not be published. Required fields are marked *


John Galt

John Galt

Explanation from link:

The ApplyCurrentValues method is used to apply changes that were made to objects outside the ObjectContext, such as detached objects that are received by a Web service. The method copies the scalar values from the supplied object into the object in the ObjectContext that has the same key.

So the reason it’s C and D, is because changes were applied to localCustomer.