Export (0) Print
Expand All

MergeOption Enumeration

Specifies how objects being loaded into the object context are merged with objects already in the object context.

Namespace:  System.Data.Objects
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public enum MergeOption

Member nameDescription
AppendOnlyObjects 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.
NoTrackingObjects 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.
OverwriteChangesObjects 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.
PreserveChangesObjects 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.

In the .NET Framework version 4, the Entity Framework compares the current values of unmodified properties with the values that were returned from the data source. If the values are not the same, the property is marked as modified.

In the .NET Framework version 3.5 SP1, the Entity Framework does not mark the property as modified, even if the value in the data source is different.

Only modified properties are persisted to the data source when you call SaveChanges.

To preserve the 3.5 SP1 behavior, set UseLegacyPreserveChangesBehavior to true. The PreserveChanges option can be used to resolve optimistic concurrency exceptions while preserving changes in the local context. For more information, see Saving Changes and Managing Concurrency (Entity Framework).

The Entity Framework only maintains a single instance of an object with a specific entity key in the cache. The EntityKey objects are immutable objects that that represent object's identity. Entity keys are used to perform identity resolution in the object context. For more information, see Working with Entity Keys. If an entity with the same identity is already being tracked, the data coming from the data source and the data already in the state manager are merged according to the MergeOption of the query.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft