Share via


ObjectContext.SaveChanges Method

Definition

Overloads

SaveChanges()

Persists all updates to the database and resets change tracking in the object context.

SaveChanges(Boolean)
Obsolete.

Persists all updates to the database and optionally resets change tracking in the object context.

SaveChanges(SaveOptions)

Persists all updates to the database and optionally resets change tracking in the object context.

SaveChanges()

Persists all updates to the database and resets change tracking in the object context.

public virtual int SaveChanges ();
abstract member SaveChanges : unit -> int
override this.SaveChanges : unit -> int
Public Overridable Function SaveChanges () As Integer

Returns

The number of state entries written to the underlying database. This can include state entries for entities and/or relationships. Relationship state entries are created for many-to-many relationships and relationships where there is no foreign key property included in the entity class (often referred to as independent associations).

Exceptions

An optimistic concurrency violation has occurred while saving changes.

Applies to

SaveChanges(Boolean)

Caution

Use SaveChanges(SaveOptions options) instead.

Persists all updates to the database and optionally resets change tracking in the object context.

[System.ComponentModel.Browsable(false)]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[System.Obsolete("Use SaveChanges(SaveOptions options) instead.")]
public virtual int SaveChanges (bool acceptChangesDuringSave);
abstract member SaveChanges : bool -> int
override this.SaveChanges : bool -> int
Public Overridable Function SaveChanges (acceptChangesDuringSave As Boolean) As Integer

Parameters

acceptChangesDuringSave
Boolean

This parameter is needed for client-side transaction support. If true, the change tracking on all objects is reset after SaveChanges(Boolean) finishes. If false, you must call the AcceptAllChanges() method after SaveChanges(Boolean).

Returns

The number of state entries written to the underlying database. This can include state entries for entities and/or relationships. Relationship state entries are created for many-to-many relationships and relationships where there is no foreign key property included in the entity class (often referred to as independent associations).

Attributes

Exceptions

An optimistic concurrency violation has occurred while saving changes.

Applies to

SaveChanges(SaveOptions)

Persists all updates to the database and optionally resets change tracking in the object context.

public virtual int SaveChanges (System.Data.Entity.Core.Objects.SaveOptions options);
abstract member SaveChanges : System.Data.Entity.Core.Objects.SaveOptions -> int
override this.SaveChanges : System.Data.Entity.Core.Objects.SaveOptions -> int
Public Overridable Function SaveChanges (options As SaveOptions) As Integer

Parameters

options
SaveOptions

A SaveOptions value that determines the behavior of the operation.

Returns

The number of state entries written to the underlying database. This can include state entries for entities and/or relationships. Relationship state entries are created for many-to-many relationships and relationships where there is no foreign key property included in the entity class (often referred to as independent associations).

Exceptions

An optimistic concurrency violation has occurred while saving changes.

Applies to