ObjectContext.SaveChanges Method (SaveOptions)

.NET Framework (current version)

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Persists all updates to the data source with the specified SaveOptions.

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

public virtual int SaveChanges(
	SaveOptions options


Type: System.Data.Objects.SaveOptions

A SaveOptions value that determines the behavior of the operation.

Return Value

Type: System.Int32

The number of objects in an Added, Modified, or Deleted state when SaveChanges was called.

Exception Condition

An optimistic concurrency violation has occurred.

Use this specific overload of SaveChanges to either make sure that DetectChanges is called before you save changes to the data source or that AcceptAllChanges is called after you save changes to the data source.

This enumeration has a FlagsAttribute that allows for a bitwise combination of its member values.

To make sure that objects on the client have been updated by data source-side logic, you can call the Refresh method with the StoreWins value after you call SaveChanges. The SaveChanges method operates in a transaction. SaveChanges will roll back that transaction and throw an exception if any one of the dirty ObjectStateEntry objects cannot be persisted.

If an optimistic concurrency violation has occurred, an OptimisticConcurrencyException is thrown. You can resolve an optimistic concurrency violation by catching it, calling the Refresh method with the StoreWins or ClientWins values, and then calling the SaveChanges method again. For more information, see How to: Manage Data Concurrency in the Object Context.

.NET Framework
Available since 4.0
Return to top