BB84.EntityFrameworkCore.Repositories 4.5.725

There is a newer version of this package available.
See the version list below for details.
dotnet add package BB84.EntityFrameworkCore.Repositories --version 4.5.725
                    
NuGet\Install-Package BB84.EntityFrameworkCore.Repositories -Version 4.5.725
                    
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="BB84.EntityFrameworkCore.Repositories" Version="4.5.725" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BB84.EntityFrameworkCore.Repositories" Version="4.5.725" />
                    
Directory.Packages.props
<PackageReference Include="BB84.EntityFrameworkCore.Repositories" />
                    
Project file
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 BB84.EntityFrameworkCore.Repositories --version 4.5.725
                    
#r "nuget: BB84.EntityFrameworkCore.Repositories, 4.5.725"
                    
#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 BB84.EntityFrameworkCore.Repositories@4.5.725
                    
#: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=BB84.EntityFrameworkCore.Repositories&version=4.5.725
                    
Install as a Cake Addin
#tool nuget:?package=BB84.EntityFrameworkCore.Repositories&version=4.5.725
                    
Install as a Cake Tool

net80 net100 NuGet

BB84.EntityFrameworkCore.Repositories

This package provides the default repository implementations and DatabaseFacadeExtensions for calling stored procedures and SQL functions.

Installation

dotnet add package BB84.EntityFrameworkCore.Repositories

Repository implementations

GenericRepository<TEntity>

Abstract base for all repositories. Accepts IDbContext as a constructor parameter. All query methods delegate to PrepareQuery(...), which composes Where, IgnoreQueryFilters, Include, OrderBy, Skip, Take, and AsNoTracking into a single IQueryable<TEntity>. Projection overloads use the protected ApplyProjection(query, selector, fieldSelector) helper.

Streaming reads

StreamAll and StreamByCondition return IAsyncEnumerable<T> instead of IReadOnlyList<T>. They take the same parameters as their GetAllAsync / GetManyByConditionAsync counterparts and go through the same PrepareQuery(...) composition, but the result set is not buffered — rows are yielded as they arrive. Use them for exports, batch jobs and other unbounded reads:

await foreach (Product product in repository.StreamByCondition(
    p => p.IsActive,
    orderBy: q => q.OrderBy(p => p.Name),
    token: token))
{
    await writer.WriteAsync(product, token);
}

Two things to keep in mind:

  • The sequence is lazy. It must be enumerated within the lifetime of the IDbContext, and EF Core allows only one active stream per context at a time.
  • trackChanges defaults to false and should stay that way for large reads — with tracking enabled the change tracker grows with every yielded entity, which defeats the purpose of streaming.

Subclasses can build their own streaming methods on the protected QueryManyStream(...) helpers, which mirror QueryMany / QueryManyAsync in both the entity and the projection flavour.

IdentityRepository<TEntity, TKey> / IdentityRepository<TEntity>

Extends GenericRepository<TEntity> with key-based GetById, GetByIds, and bulk Delete/Update by ID. The non-generic overload defaults TKey to Guid.

EnumeratorRepository<TEntity, TKey> / EnumeratorRepository<TEntity>

Extends IdentityRepository with GetByName and GetByNames. The non-generic overload defaults TKey to int.

Usage

Inherit from the appropriate base class and inject IDbContext:

public class ProductRepository : IdentityRepository<Product>, IProductRepository
{
    public ProductRepository(IDbContext dbContext) : base(dbContext) { }

    public async Task<IReadOnlyList<Product>> GetByCategoryAsync(
        int categoryId, CancellationToken token = default)
        => await GetManyByConditionAsync(
            p => p.CategoryId == categoryId,
            orderBy: q => q.OrderBy(p => p.Name),
            token: token);
}

public class CategoryRepository : EnumeratorRepository<ProductCategory>, ICategoryRepository
{
    public CategoryRepository(IDbContext dbContext) : base(dbContext) { }
    // GetByName / GetByNames inherited
}

DI registration:

services.AddScoped<IProductRepository, ProductRepository>();
services.AddScoped<ICategoryRepository, CategoryRepository>();

Calling save changes is the responsibility of the caller (unit-of-work pattern):

repository.Create(entity);
await dbContext.SaveChangesAsync(token);

DatabaseFacadeExtensions

Extension methods on DatabaseFacade (context.Database) for calling SQL Server stored procedures and functions safely with parameterized SQL.

Stored procedures

// Returns rows as IReadOnlyList<T>
IReadOnlyList<ReportRow> rows = context.Database.ExecuteProcedure<ReportRow>(
    schema: "dbo",
    name: "usp_GetReport",
    parameters: [new SqlParameter("@FromDate", fromDate)]);

// Non-generic overload returns rows-affected count
int affected = context.Database.ExecuteProcedure(
    schema: "dbo",
    name: "usp_ArchiveOrders",
    parameters: [new SqlParameter("@CutoffDate", cutoff)]);

// Async variants
await context.Database.ExecuteProcedureAsync<ReportRow>(..., cancellationToken);
await context.Database.ExecuteProcedureAsync(..., cancellationToken);

Output parameters are supported — parameters with Direction = ParameterDirection.Output are emitted as @param = @param OUTPUT in the generated SQL.

Table-valued functions

IReadOnlyList<ProductDto> results = context.Database.ExecuteTableFunction<ProductDto>(
    schema: "dbo",
    name: "fn_GetActiveProducts",
    parameters: [new SqlParameter("@CategoryId", categoryId)]);

await context.Database.ExecuteTableFunctionAsync<ProductDto>(..., cancellationToken);

Scalar-valued functions

decimal? total = context.Database.ExecuteScalarFunction<decimal>(
    schema: "dbo",
    name: "fn_GetOrderTotal",
    parameters: [new SqlParameter("@OrderId", orderId)]);

await context.Database.ExecuteScalarFunctionAsync<decimal>(..., cancellationToken);

All methods sanitize schema/name inputs and use parameterized SQL to prevent injection.

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.  net9.0 was computed.  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 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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on BB84.EntityFrameworkCore.Repositories:

Package Downloads
BB84.EntityFrameworkCore.Repositories.SqlServer

This package contains the SqlServer specific tuning of the entity type configurations, column type extensions and DatabaseFacade extensions for the use of EntityFrameworkCore with SqlServer.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.1020 102 10/20/2026
5.0.916 405 9/16/2026
5.0.818 305 8/18/2026
4.5.725 223 7/25/2026
4.4.724 140 7/24/2026
4.4.625 229 6/25/2026
4.3.520 316 5/20/2026
4.3.513 198 5/13/2026
4.3.507 154 5/7/2026
4.3.419 249 4/19/2026
4.3.327 288 3/27/2026
4.2.322 179 3/22/2026
4.1.319 161 3/19/2026
4.1.222 246 2/22/2026
4.1.122 219 1/22/2026
4.0.1026 408 10/26/2025
4.0.916 472 9/16/2025
4.0.817 316 8/17/2025
3.1.617 394 6/17/2025
3.1.518 280 5/18/2025
Loading failed