Note
Access to this page requires authorization. You can try signing in or .
Access to this page requires authorization. You can try .
DbContext.SaveChanges Method
Definition
- Namespace:
- Microsoft.EntityFrameworkCore
- Assembly:
- Microsoft.EntityFrameworkCore.dll
- Package:
- Microsoft.EntityFrameworkCore v1.0.6
- Package:
- Microsoft.EntityFrameworkCore v1.1.6
- Package:
- Microsoft.EntityFrameworkCore v10.0.0
- Package:
- Microsoft.EntityFrameworkCore v2.0.3
- Package:
- Microsoft.EntityFrameworkCore v2.1.11
- Package:
- Microsoft.EntityFrameworkCore v2.2.6
- Package:
- Microsoft.EntityFrameworkCore v3.0.0
- Package:
- Microsoft.EntityFrameworkCore v3.1.0
- Package:
- Microsoft.EntityFrameworkCore v5.0.0
- Package:
- Microsoft.EntityFrameworkCore v6.0.0
- Package:
- Microsoft.EntityFrameworkCore v7.0.0
- Package:
- Microsoft.EntityFrameworkCore v8.0.0
- Package:
- Microsoft.EntityFrameworkCore v9.0.0
Important
Some information relates to prerelease product that may be substantially modified before itβs released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
| Name | Description |
|---|---|
| SaveChanges(Boolean) |
Saves all changes made in this context to the database. |
| SaveChanges() |
Saves all changes made in this context to the database. |
SaveChanges(Boolean)
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
Saves all changes made in this context to the database.
[System.Diagnostics.DebuggerStepThrough]
public virtual int SaveChanges(bool acceptAllChangesOnSuccess);
public virtual int SaveChanges(bool acceptAllChangesOnSuccess);
[<System.Diagnostics.DebuggerStepThrough>]
abstract member SaveChanges : bool -> int
override this.SaveChanges : bool -> int
abstract member SaveChanges : bool -> int
override this.SaveChanges : bool -> int
Public Overridable Function SaveChanges (acceptAllChangesOnSuccess As Boolean) As Integer
Parameters
- acceptAllChangesOnSuccess
- Boolean
Indicates whether AcceptAllChanges() is called after the changes have been sent successfully to the database.
Returns
The number of state entries written to the database.
- Attributes
Exceptions
An error is encountered while saving to the database.
A concurrency violation is encountered while saving to the database. A concurrency violation occurs when an unexpected number of rows are affected during save. This is usually because the data in the database has been modified since it was loaded into memory.
Remarks
This method will automatically call DetectChanges() to discover any changes to entity instances before saving to the underlying database. This can be disabled via AutoDetectChangesEnabled.
Entity Framework Core does not support multiple parallel operations being run on the same DbContext instance. This includes both parallel execution of async queries and any explicit concurrent use from multiple threads. Therefore, always await async calls immediately, or use separate DbContext instances for operations that execute in parallel. See Avoiding DbContext threading issues for more information and examples.
See Saving data in EF Core for more information and examples.
Applies to
SaveChanges()
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
- Source:
- DbContext.cs
Saves all changes made in this context to the database.
[System.Diagnostics.DebuggerStepThrough]
public virtual int SaveChanges();
public virtual int SaveChanges();
[<System.Diagnostics.DebuggerStepThrough>]
abstract member SaveChanges : unit -> int
override this.SaveChanges : unit -> int
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 database.
- Attributes
Exceptions
An error is encountered while saving to the database.
A concurrency violation is encountered while saving to the database. A concurrency violation occurs when an unexpected number of rows are affected during save. This is usually because the data in the database has been modified since it was loaded into memory.
Remarks
This method will automatically call DetectChanges() to discover any changes to entity instances before saving to the underlying database. This can be disabled via AutoDetectChangesEnabled.
Entity Framework Core does not support multiple parallel operations being run on the same DbContext instance. This includes both parallel execution of async queries and any explicit concurrent use from multiple threads. Therefore, always await async calls immediately, or use separate DbContext instances for operations that execute in parallel. See Avoiding DbContext threading issues for more information and examples.
See Saving data in EF Core for more information and examples.
Applies to
Entity Framework
Feedback
Was this page helpful?
