EntityFrameworkCore.Concurrency 8.0.1

dotnet add package EntityFrameworkCore.Concurrency --version 8.0.1                
NuGet\Install-Package EntityFrameworkCore.Concurrency -Version 8.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EntityFrameworkCore.Concurrency" Version="8.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EntityFrameworkCore.Concurrency --version 8.0.1                
#r "nuget: EntityFrameworkCore.Concurrency, 8.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EntityFrameworkCore.Concurrency as a Cake Addin
#addin nuget:?package=EntityFrameworkCore.Concurrency&version=8.0.1

// Install EntityFrameworkCore.Concurrency as a Cake Tool
#tool nuget:?package=EntityFrameworkCore.Concurrency&version=8.0.1                

SaveableEntities and DbContextExtensions

.NET

This package adds the ability for applications using Entity Framework to handle concurrency conflicts automatically. These changes can either be done on interfaces/classes that extend the ISaveableEntities interface or DbContext objects. Using this package requires the project to be on .NET 6.0 or newer. These packages should only be used with projects using EntityFramework version 6.x.x or higher on .NET 6.0, version 7.x.x on .NET 7.0, and version 8.x.x on .NET 8.0.

ISaveableEntities Interface

This adds the SaveChangesAsync method to an interface. This will allow changes to the entities to be saved to the database.

SaveChangesAsync overloads

This will save changes like above, but will also try to resolve any concurrency conflicts it encounters during the operation. Optionally, consumers can specify the conflict approach to take and the number of retries to attempt before failing. This method can be used by either interfaces/classes that extend the ISaveableEntities interface or DbContext objects.

There are a few different options to approach conflicts:

  • Default: Follows the default path when concurrent conflicts are encountered, which is to throw a DbUpdateConcurrencyException exception
  • ForceUpdate: Forces the property to overwrite whatever is currently set in the database.
  • SkipConflicts: Skips conflicting values to leave whatever is currently set in the database.

These approaches will be taken if the record is modified or removed between the time your context found and modified a record.

The following table shows how each approach will resolve concurrency issues. Record 1 is what the application is currently trying to set the record property to. Record 2 shows what operation happened to the record prior to our update, creating a concurrency conflict.

Record 1 Value Record 2 Value Approach Resulting Value
Apple Orange Default Exception thrown
Apple Orange ForceUpdate Apple
Apple Orange SkipConflicts Orange
Apple Record Removed Default Exception thrown
Apple Record Removed ForceUpdate Apple
Apple Record Removed SkipConflicts Record Removed

Please Note: This method can still throw exceptions if a non-concurrency exception is raised or if the retry limit was exceeded, so consumers should still add error handling around their save operations.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.1 121 6/17/2024
8.0.0 262 11/15/2023
7.3.0 157 8/3/2023
7.2.0 139 7/30/2023
7.1.0 211 3/7/2023
7.0.0 248 2/23/2023
6.1.0 219 3/7/2023
6.0.0 241 2/23/2023