LeanDb.EntityFrameworkCore
0.1.3
dotnet add package LeanDb.EntityFrameworkCore --version 0.1.3
NuGet\Install-Package LeanDb.EntityFrameworkCore -Version 0.1.3
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="LeanDb.EntityFrameworkCore" Version="0.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LeanDb.EntityFrameworkCore" Version="0.1.3" />
<PackageReference Include="LeanDb.EntityFrameworkCore" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LeanDb.EntityFrameworkCore --version 0.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LeanDb.EntityFrameworkCore, 0.1.3"
#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.
#:package LeanDb.EntityFrameworkCore@0.1.3
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LeanDb.EntityFrameworkCore&version=0.1.3
#tool nuget:?package=LeanDb.EntityFrameworkCore&version=0.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
LeanDb.EntityFrameworkCore
Entity Framework Core query implementation for LeanDb. Use this package to execute LeanDb queries against any database via EF Core DbContext.
Usage
// Define a query
public record GetUserCount : IQuery<int>;
// Define its EF Core implementation
public class GetUserCountImplementation : IEfCoreQueryImplementation<AppDbContext, int>
{
public GetUserCountImplementation(GetUserCount _) { }
public async Task<int> Execute(AppDbContext dbContext, CancellationToken cancellationToken)
=> await dbContext.Users.CountAsync(cancellationToken);
}
// Register with DI
services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(connectionString));
services.AddEfCoreDb<AppDbContext>(options =>
options.LoadImplementationsFromAssembly(typeof(GetUserCountImplementation)));
// Execute
var db = serviceProvider.GetRequiredService<EfCoreDb<AppDbContext>>();
var count = await db.Execute(new GetUserCount());
How it works
- Define a query — create a record or class implementing
IQuery<TResult>. - Implement the query — create a class implementing
IEfCoreQueryImplementation<TDbContext, TResult>. The implementation receives the typedTDbContextand executes the query using EF Core methods. - Register — call
AddEfCoreDb<TDbContext>()on yourIServiceCollection, pointing to the assembly that contains your implementations. - Execute — resolve
EfCoreDb<TDbContext>and callExecute(query).
Registration
services.AddEfCoreDb<TDbContext>(options =>
{
// Required: scan an assembly for query implementations
options.LoadImplementationsFromAssembly(typeof(SomeImplementation));
// Optional: scan additional assemblies
options.LoadImplementationsFromAssembly(typeof(OtherImplementation));
});
The EfCoreDb<TDbContext> is registered as scoped, matching the typical lifetime of an EF Core DbContext.
Requirements
- .NET 10 or later
Microsoft.EntityFrameworkCore.SqlServer(or your EF Core provider of choice)LeanDbandLeanDb.ImplementationAbstractions
Related packages
| Package | Description |
|---|---|
| LeanDb | Core abstractions — define queries in your domain layer |
| LeanDb.ImplementationAbstractions | Helper base types for building custom implementations |
| LeanDb.Dapper | Alternative Dapper-based query implementation |
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- LeanDb (>= 0.1.3)
- LeanDb.ImplementationAbstractions (>= 0.1.3)
- Microsoft.EntityFrameworkCore.SqlServer (>= 10.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.