OnTran.EF.SCU
1.0.0.2
dotnet add package OnTran.EF.SCU --version 1.0.0.2
NuGet\Install-Package OnTran.EF.SCU -Version 1.0.0.2
<PackageReference Include="OnTran.EF.SCU" Version="1.0.0.2" />
<PackageVersion Include="OnTran.EF.SCU" Version="1.0.0.2" />
<PackageReference Include="OnTran.EF.SCU" />
paket add OnTran.EF.SCU --version 1.0.0.2
#r "nuget: OnTran.EF.SCU, 1.0.0.2"
#:package OnTran.EF.SCU@1.0.0.2
#addin nuget:?package=OnTran.EF.SCU&version=1.0.0.2
#tool nuget:?package=OnTran.EF.SCU&version=1.0.0.2
OnTran.EF.SCU
Use your EF-based code without any changes, without raw SQL, without breaking the transactionality and without application crashes due to OutOfMemory errors.
Minimal, Effective, multi-target EF Core extension for run short-lived contexts on the same connection and transaction when micro-ORM cannot be used.
Short-lived contexts will be used as the SQL formatter, without storing all inserted objects in the application memory due to the short lifetime of the scoped context.
Support DB types:
✅ MySql-based
✅ Postgres-based
✅ MS Sql
- Other database types can be used, but testing was only done on these three.
Examples-Tests These tests on .net8.0 and use TestContainers to run DB in Docker.
If the functionality of this solution does not meet your needs, feel free to make your own version of this extension or just copy-paste code in your solution and change. It is open source.
Nuget
multi-target package:
✅ .net6.0
✅ .net7.0
✅ .net8.0
✅ .net9.0
https://www.nuget.org/packages/OnTran.EF.SCU
dotnet add package OnTran.EF.SCU
or
NuGet\Install-Package OnTran.EF.SCU
Example of using
using OnTran.EF.SCU;
await using var tran = await context.Database.BeginTransactionAsync(token);
//Get IServiceScopeFactory from DI to use this extension (via constructor of your class or via ServiceProvider).
var affected = await context.Database.ConstructScopedContextOnCurrentTranAsync<DBContext, int>(serviceScopeFactory, async (db, scope) =>
{
// The 'db' instance from the functor is not equal to the 'context' instance. 'db' is a context instance without its own connection and transaction, it uses conn/tran from 'context'.
for (var i = 0; i < 1000; i++)
{
db.TestEntities.Add(new TestEntity { Value = i.ToString() });
}
return await db.SaveChangesAsync(token);
}, token);
//all TestEntity will be gone (not immediately) from memory because 'db' context from the method above is disposed.
await context.Database.ConstructScopedContextOnCurrentTranAsync<DBContext>(serviceScopeFactory, async (db, scope) =>
{
for (var i = 0; i < 1000; i++)
{
db.TestEntities.Add(new TestEntity { Value = i.ToString() });
}
await db.SaveChangesAsync(token);
}, token);
//all TestEntity will be gone (not immediately) from memory because 'db' context from the method above is disposed.
await context.Database.ConstructScopedContextOnCurrentTranAsync<DBContext>(serviceScopeFactory, async (db, scope) =>
{
await scope.GetService<MyService>().ProcessManyRecordsAndInsertManyRecordsWithComplicatedLogicAsync(token);
//DB context instance from DI in MyService instance from scope.GetService<MyService>() will use not own transaction/connetion, but you main tran/conn.
//So, you can use any services via DI without code changes.
}, token);
//all TestEntity will be gone (not immediately) from memory because 'db' context from the method above is disposed.
await tran.CommitAsync(token);
License
Free MIT license (https://github.com/sapozhnikovv/OnTran.EF.SCU/blob/main/LICENSE)
| Product | Versions 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net6.0
- Microsoft.EntityFrameworkCore (>= 6.0.0 && < 7.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 6.0.0 && < 7.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0 && < 7.0.0)
-
net7.0
- Microsoft.EntityFrameworkCore (>= 7.0.0 && < 8.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 7.0.0 && < 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0 && < 8.0.0)
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.0 && < 9.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.0 && < 9.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0 && < 9.0.0)
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.0 && < 10.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 9.0.0 && < 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0 && < 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.