Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

ObjectContext.Refresh Method (RefreshMode, IEnumerable)

Updates a collection of objects in the object context with data from the data source.

Namespace:  System.Data.Objects
Assembly:  System.Data.Entity (in System.Data.Entity.dll)
public void Refresh(
	RefreshMode refreshMode,
	IEnumerable collection
)

Parameters

refreshMode
Type: System.Data.Objects.RefreshMode
A RefreshMode value that indicates whether property changes in the object context are overwritten with property values from the data source.
collection
Type: System.Collections.IEnumerable
An IEnumerable collection of objects to refresh.
ExceptionCondition
ArgumentNullException

collection is null.

ArgumentOutOfRangeException

refreshMode is not valid.

ArgumentException

collection is empty.

-or-

An object is not attached to the context.

This method has the dual purpose of allowing objects in the object context to be refreshed with data from the data source, and being the mechanism by which conflicts can be resolved. For more information, see Saving Changes and Managing Concurrency (Entity Framework).

The order in which objects are refreshed is nondeterministic.

After Refresh is called, the object’s original values will always be updated with the data source value, but the current values might or might not be updated with the data source value. This depends on the RefreshMode value. The StoreWins mode means that the objects in the collection should be updated to match the data source values. ClientWins means that only the changes in the object context will be persisted, even if there have been other changes in the data source.

To ensure that objects have been updated by data source-side logic, you can call Refresh with StoreWins after you call the SaveChanges method.

.NET Framework

Supported in: 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.