You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create a multi-tier application.
You use Microsoft ADO.NET Entity Data Model (EDM) to model entities.
The model contains entities named SalesOrderHeader and SalesOrderDetail.
For performance considerations in querying SalesOrderHeader, you detach SalesOrderDetail entities from ObjectContext.
You need to ensure that changes made to existing SalesOrderDetail entities updated in other areas of your application are persisted to the database.
Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)
A.
Re-attach the SalesOrderDetail entities.
B.
Set the MergeOption of SalesOrderDetail to MergeOptions.OverwriteChanges.
C.
Set the MergeOption of SalesOrderDetail to MergeOptions.NoTracking.
D.
Call ObjectContext.ApplyCurrentValue.
E.
Call ObjectContext.ApplyOriginalValue.
Explanation:
ApplyCurrentValues(Of TEntity) Copies the scalar values from the supplied object into the object in the ObjectContext that has the same key.
The ApplyCurrentValues<TEntity> 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. You can use the EntityKey of the detached object to retrieve an instance
of this object from the data source. Any values that differ from the original values of the object are marked as modified.
Note, the method does not apply the current values to the related objects of currentEntity.
ApplyOriginalValues(Of TEntity) Copies the scalar values from the supplied object into set of original values for the object in the ObjectContext that has the same key.
The ApplyOriginalValues<TEntity> 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. You can use the EntityKey of the detached object to retrieve an instance
of this object from the data source. Any values that differ from the current values of the object are marked as modified.
Note, the method does not apply the current values to the related objects of originalEntity.
What’s the scenario for this?? Just Attach and call ApplyOriginalValues doesn’t save changes…
0
0
You also need to call SaveChanges() at the end, but A and E are the correct answers. Here’s an article from Microsoft that proves it:
How to: Apply Changes Made to a Detached Object
http://msdn.microsoft.com/en-us/library/vstudio/bb896248%28v=vs.100%29.aspx
context.SalesOrderDetails.Attach(updatedItem);
context.ApplyOriginalValues(“SalesOrderDetails”, originalItem);
context.SaveChanges();
0
0