Zack.EFCore.Batch 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Zack.EFCore.Batch --version 1.1.0                
NuGet\Install-Package Zack.EFCore.Batch -Version 1.1.0                
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="Zack.EFCore.Batch" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Zack.EFCore.Batch --version 1.1.0                
#r "nuget: Zack.EFCore.Batch, 1.1.0"                
#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 Zack.EFCore.Batch as a Cake Addin
#addin nuget:?package=Zack.EFCore.Batch&version=1.1.0

// Install Zack.EFCore.Batch as a Cake Tool
#tool nuget:?package=Zack.EFCore.Batch&version=1.1.0                

Zack.EFCore.Batch

中文文档 Chinese version

Using this library, Entity Framework Core users can delete or update multiple records from a LINQ Query in a SQL statement without loading entities. This libary supports Entity Framework Core 5.0 and above.

Instructions:
Step 1:

 Install-Package Zack.EFCore.Batch

Step 2: Add the following code into OnConfiguring() method of your DbContext

 optionsBuilder.UseBatchEF();

Step 3: Use the extension method DeleteRangeAsync() of DbContext to delete a set of records. The parameter of DeleteRangeAsync() is the lambda expression of the filter Example code:

await ctx.DeleteRangeAsync<Book>(b => b.Price > n || b.AuthorName == "zack yang"); 

The code above will execute the following SQL statement on database:

Delete FROM [T_Books] WHERE ([Price] > @__p_0) OR ([AuthorName] = @__s_1)

and the DeleteRange() is the synchronous version of DeleteRangeAsync().

Use the extension method BatchUpdate() of DbContext to create a BatchUpdateBuilder. There are four methods in BatchUpdateBuilder as follows

  • Set() is used for assigning a value to a property. The first parameter of the method is the lambda expression of the property, and the second one is the lambda expression of the value.
  • Where() is used for setting the filter expression
  • ExecuteAsync() is an asynchronous method that can execute the BatchUpdateBuilder, and the Execute() is a synchronous alternative of ExecuteAsync()

Example code:

await ctx.BatchUpdate<Book>()
    .Set(b => b.Price, b => b.Price + 3)
    .Set(b => b.Title, b => s)
    .Set(b => b.AuthorName,b=>b.Title.Substring(3,2)+b.AuthorName.ToUpper())
    .Set(b => b.PubTime, b => DateTime.Now)
    .Where(b => b.Id > n || b.AuthorName.StartsWith("Zack"))
    .ExecuteAsync();

The code above will execute the following SQL statement on database:

Update [T_Books] SET [Price] = [Price] + 3.0E0, [Title] = @__s_1, [AuthorName] = COALESCE(SUBSTRING([Title], 3 + 1, 2), N'') + COALESCE(UPPER([AuthorName]), N''), [PubTime] = GETDATE()
WHERE ([Id] > @__p_0) OR ([AuthorName] IS NOT NULL AND ([AuthorName] LIKE N'Zack%'))

This library utilizes the EF Core to translate the lambda expression to SQL statement, so it supports nearly all the lambda expressions which EF Core supports.

The following databases have been tested that they can work well with Zack.EFCore.Batch: MS SQLServer(Microsoft.EntityFrameworkCore.SqlServer), MySQL(Pomelo.EntityFrameworkCore.MySql), PostgreSQL(Npgsql.EntityFrameworkCore.PostgreSQL). In theory, as long as a database has its EF Core 5 Provider , the database can be supported by this library. In another words, if you are using a database that does not already have an EF Core 5 Provider, the library will not support it either.

Report of this library

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on Zack.EFCore.Batch:

Package Downloads
Zack.EFCore.Batch.Sqlite

A Sqlite-specific version of Zack.EFCore.Batch. Using this library, Entity Framework Core users can delete or update multiple records from a LINQ Query in a SQL statement without loading entities. This libary supports Entity Framework Core 5.0. As for EF Core 6 users, please use Zack.EFCore.Batch.Sqlite_NET6.

Zack.EFCore.Batch.MySQL.Pomelo

A MySQL(Pomelo)-specific version of Zack.EFCore.Batch. Using this library, Entity Framework Core users can delete or update multiple records from a LINQ Query in a SQL statement without loading entities. This libary supports Entity Framework Core 5.0 and above.

Zack.EFCore.Batch.MSSQL

A MSSQL-specific version of Zack.EFCore.Batch. Using this library, Entity Framework Core users can delete or update multiple records from a LINQ Query in a SQL statement without loading entities. This libary supports Entity Framework Core 5.0. As for EF Core 6 users, please use Zack.EFCore.Batch.MSSQL_NET6

Zack.EFCore.Batch.Npgsql

A Postgresql-specific version of Zack.EFCore.Batch. Using this library, Entity Framework Core users can delete or update multiple records from a LINQ Query in a SQL statement without loading entities. This libary supports Entity Framework Core 5.0. As for EF Core 6 users, please use Zack.EFCore.Batch.Npgsql_NET6.

Zack.EFCore.Batch.Oracle

A Oracle-specific version of Zack.EFCore.Batch. Using this library, Entity Framework Core users can delete or update multiple records from a LINQ Query in a SQL statement without loading entities. This libary supports Entity Framework Core 5.0.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.6.9 723 1/26/2024
1.6.8 412 12/12/2023
1.6.6 2,371 11/17/2023
1.6.3 9,180 9/5/2022
1.6.2 1,927 7/29/2022
1.6.1 1,633 7/16/2022
1.6.0 1,559 7/12/2022
1.5.15 3,836 4/20/2022
1.5.14 1,492 4/19/2022
1.5.13 1,509 4/19/2022
1.5.12 1,569 4/11/2022
1.5.11 4,621 1/22/2022
1.5.10 1,395 1/21/2022
1.5.9 466 1/10/2022
1.5.8 4,243 12/20/2021
1.5.7 749 12/20/2021
1.5.6 1,253 12/14/2021
1.5.5 1,013 12/13/2021
1.5.4 789 12/10/2021
1.5.3 16,602 12/2/2021
1.5.1 835 12/2/2021
1.5.0 2,554 12/1/2021
1.4.8 59,417 8/5/2021
1.4.7 1,270 8/4/2021
1.4.6 9,825 6/21/2021
1.4.5 22,375 6/10/2021
1.4.4 1,210 6/10/2021
1.4.3 1,411 6/7/2021
1.4.2 451 6/7/2021
1.4.0 426 6/4/2021
1.3.0 2,662 6/3/2021
1.2.6 7,021 4/20/2021
1.2.5 1,011 4/19/2021
1.2.4 1,263 2/27/2021
1.2.3 479 12/30/2020
1.2.2 893 12/30/2020
1.2.1 968 12/25/2020
1.2.0 735 12/25/2020
1.1.2 638 12/17/2020
1.1.1 545 12/16/2020
1.1.0 466 11/27/2020
1.0.3 432 11/26/2020
1.0.2 402 11/25/2020
1.0.1 438 11/25/2020
1.0.0 500 11/25/2020