XyloCode.EFCore.Extensions
1.0.1
Prefix Reserved
dotnet add package XyloCode.EFCore.Extensions --version 1.0.1
NuGet\Install-Package XyloCode.EFCore.Extensions -Version 1.0.1
<PackageReference Include="XyloCode.EFCore.Extensions" Version="1.0.1" />
<PackageVersion Include="XyloCode.EFCore.Extensions" Version="1.0.1" />
<PackageReference Include="XyloCode.EFCore.Extensions" />
paket add XyloCode.EFCore.Extensions --version 1.0.1
#r "nuget: XyloCode.EFCore.Extensions, 1.0.1"
#:package XyloCode.EFCore.Extensions@1.0.1
#addin nuget:?package=XyloCode.EFCore.Extensions&version=1.0.1
#tool nuget:?package=XyloCode.EFCore.Extensions&version=1.0.1
EF Core (Bulk) Extensions
An EF Core extension library for high-performance bulk data synchronization using SQL MERGE, supporting both IEnumerable<T> and IAsyncEnumerable<T> data sources.
The library is optimized for working with DevExpress XAF system fields (GCRecord, OptimisticLockField), as well as custom versioning and change-tracking fields (RowState, RowStamp). It supports state-aware record processing, including handling of deleted objects, and provides utilities for temporarily disabling foreign key constraint checks during synchronization operations.
Supported Databases
- Microsoft SQL Server
- Microsoft Azure SQL Database
How to use
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using XyloCode.EFCore.Extensions;
namespace XyloCode.EFCore.Examples
{
internal class SimpleFiller
{
private readonly SimpleEFCoreDbContext _dbContext;
private readonly Channel<Country> _countryChannel = Channel.CreateUnbounded<Country>();
public SimpleFiller(SimpleEFCoreDbContext dbContext)
{
_dbContext = dbContext;
}
public Task CountryMergeAsync(IEnumerable<Country> countries, CancellationToken cancellationToken = default)
{
var copyConfig = new EFCoreCopyConfig
{
BulkCopyTimeout = 300,
};
return _dbContext.MergeAsync(countries, copyConfig, cancellationToken);
}
private Task<int> CountryWorkerAsync(CancellationToken cancellationToken = default)
{
var entities = _countryChannel.Reader.ReadAllAsync(cancellationToken);
var copyConfig = new EFCoreCopyConfig
{
BulkCopyTimeout = 0,
};
return _dbContext.MergeAsync(entities, copyConfig, cancellationToken);
}
public async Task AddCountryAsync(Country country, CancellationToken cancellationToken = default)
{
await _countryChannel.Writer.WriteAsync(country, cancellationToken);
}
public async Task RunAsync(CancellationToken cancellationToken = default)
{
await _dbContext.NoCheckConstraintAllAsync(typeof(Country), cancellationToken);
var t = new Task[1];
int i = 0;
t[i++] = CountryWorkerAsync(cancellationToken);
await Task.WhenAll(t);
await _dbContext.CheckConstraintAllAsync(typeof(Country), cancellationToken);
}
}
}
License
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Data.SqlClient (>= 7.1.1)
- Microsoft.EntityFrameworkCore (>= 10.0.14)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.14)
- System.Security.Cryptography.Pkcs (>= 9.0.22)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Fixed numerous bugs and improved overall stability. Renamed configuration properties and methods for better consistency and clarity. Development is ongoing.