ObjectContext::Refresh Method (RefreshMode, Object^)

 

Updates an object 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,
	Object^ entity
)

Parameters

refreshMode
Type: System.Data.Objects::RefreshMode

One of the RefreshMode values that specifies which mode to use for refreshing the ObjectStateManager.

entity
Type: System::Object^

The object to be refreshed.

Exception Condition
ArgumentNullException

collection is null.

ArgumentOutOfRangeException

refreshMode is not valid.

ArgumentException

collection is empty.

-or-

An object is not attached to the context.

Refresh has the dual purpose of allowing an object 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.

The order in which objects are refreshed is nondeterministic.

After the Refresh method 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. The StoreWins mode means that the object should be updated to match the data source values. The ClientWins value 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 an object has been updated by data source-side logic, you can call the Refresh method with the StoreWins value after you call the SaveChanges method.

This example is based on the AdventureWorks Sales Model. The example tries to save changes, and this may cause a concurrency conflict. Then it shows how to resolve the concurrency conflict by refreshing the object context before re-saving changes.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 3.5
Return to top
Show: