PrepAway - Latest Free Exam Questions & Answers

Which MergeOption enumeration value should you use to retrieve the entity?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application.
You use the ADO.NET Entity Framework Designer to model entities.
You need to retrieve an entity, and you must ensure that the entity is loaded in a detached state.
Which MergeOption enumeration value should you use to retrieve the entity?

PrepAway - Latest Free Exam Questions & Answers

A.
PreserveChanges

B.
OverwriteChanges

C.
AppendOnly

D.
NoTracking

Explanation:
AppendOnly – Objects that do not exist in the object context are attached to the context. If an object is already in the context,
the current and original values of object’s properties in the entry are not overwritten with data source values.
The state of the object’s entry and state of properties of the object in the entry do not change. AppendOnly is the default merge option.

OverwriteChanges – Objects that do not exist in the object context are attached to the context. If an object is already in the context,
the current and original values of object’s properties in the entry are overwritten with data source values.
The state of the object’s entry is set to Unchanged, no properties are marked as modified.

PreserveChanges – Objects that do not exist in the object context are attached to the context.
If the state of the entity is Unchanged, the current and original values in the entry are overwritten with data source values.
The state of the entity remains Unchanged and no properties are marked as modified.
If the state of the entity is Modified, the current values of modified properties are not overwritten with data source values.
The original values of unmodified properties are overwritten with the values from the data source.

NoTracking – Objects are maintained in a Detached state and are not tracked in the ObjectStateManager.
However, Entity Framework-generated entities and POCO entities with proxies maintain a reference to the object context to facilitate loading of related objects.

MergeOption Enumeration
(http://msdn.microsoft.com/en-us/library/system.data.objects.mergeoption.aspx)


Leave a Reply