EFCoreExtras 0.0.1

dotnet add package EFCoreExtras --version 0.0.1                
NuGet\Install-Package EFCoreExtras -Version 0.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="EFCoreExtras" Version="0.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EFCoreExtras --version 0.0.1                
#r "nuget: EFCoreExtras, 0.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 EFCoreExtras as a Cake Addin
#addin nuget:?package=EFCoreExtras&version=0.0.1

// Install EFCoreExtras as a Cake Tool
#tool nuget:?package=EFCoreExtras&version=0.0.1                

EFCoreExtras

Bulk extensions for Entity Framework Core.

Features

Bulk extensions

Bulk operations typically reduce the number of database round-trips required. This make bulk operations can often be faster than calling DbContext.SaveChangesAsync().

  • BulkCreateAsync
  • BulkUpdateAsync

Others

  • Pagination: Easily paginate IQueryable with Pagination class.

Usage

BulkCreateAsync

List<Employee> employees = [];

foreach (int i = 0; i < 1000; i++)
{
    var employee = new Employee
    {
        Name = "Name",
        Salary = 1000,
    };

    employees.Add(employee);
}

await context.BulkCreateAsync(employees, batchSize: 500);
INSERT INTO Employees (Id, Name, Salary)
VALUES (..., 'Name', 1000),
       (..., 'Name', 1000),
       (..., 'Name', 1000)

BulkUpdateAsync

var employees = context.Employees.ToList();

foreach (var employee in employees)
{
    employee.Name = $"{employee.Name} {employee.Id}"
    employee.Salary += 1000;
}

await context.BulkUpdateAsync(employees, ["Name", "Salary"]);
// Or
await context.BulkUpdateAsync(employees, [e => e.Name, e => e.Salary]);
UPDATE Employees 
SET Name = CASE 
    WHEN Id = 1 THEN '...'
    WHEN Id = 2 THEN '...'
    ...
    ELSE Name,

    Salary = CASE
    WHEN Id = 1 THEN ...
    WHEN Id = 2 THEN ...
    ...
    ELSE Salary
END
WHERE id IN (1, 2, ...)

Pagination class

var query = _dbContext.Employees.AsQueryable();

PaginatedItems<Employee> response = await Pagination.CreateAsync(pageIndex: 1, pageSize: 10, query);

return TypedResults.Ok(response);
{
    "data": [
        ...
    ],
    "pageIndex": 1,
    "pageSize": 10,
    "totalItems": 100,
    "totalPages": 10,
    "hasNextPage": true,
}

Contribution

Your contributions are always welcome! If you find any bugs or have suggestions for improvement, please feel free to open an issue or a pull request and let's sort things out.

License

This library is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET 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
0.0.1 58 5/3/2024