AkbarAmd.SharedKernel.Infrastructure.EntityFrameworkCore 1.0.27

dotnet add package AkbarAmd.SharedKernel.Infrastructure.EntityFrameworkCore --version 1.0.27
                    
NuGet\Install-Package AkbarAmd.SharedKernel.Infrastructure.EntityFrameworkCore -Version 1.0.27
                    
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="AkbarAmd.SharedKernel.Infrastructure.EntityFrameworkCore" Version="1.0.27" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AkbarAmd.SharedKernel.Infrastructure.EntityFrameworkCore" Version="1.0.27" />
                    
Directory.Packages.props
<PackageReference Include="AkbarAmd.SharedKernel.Infrastructure.EntityFrameworkCore" />
                    
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 AkbarAmd.SharedKernel.Infrastructure.EntityFrameworkCore --version 1.0.27
                    
#r "nuget: AkbarAmd.SharedKernel.Infrastructure.EntityFrameworkCore, 1.0.27"
                    
#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 AkbarAmd.SharedKernel.Infrastructure.EntityFrameworkCore@1.0.27
                    
#: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=AkbarAmd.SharedKernel.Infrastructure.EntityFrameworkCore&version=1.0.27
                    
Install as a Cake Addin
#tool nuget:?package=AkbarAmd.SharedKernel.Infrastructure.EntityFrameworkCore&version=1.0.27
                    
Install as a Cake Tool

AkbarAmd.SharedKernel.Infrastructure.EntityFrameworkCore

Clean Architecture Infrastructure Layer - EF Core Integration, Repository Implementations, and Data Access

Overview

The Infrastructure layer provides implementations for data access, external services, and framework integrations. This package specifically implements Entity Framework Core repositories and specification evaluators for database operations.

Purpose

This layer provides:

  • Repository implementations using Entity Framework Core
  • Specification evaluators for translating domain specifications to EF Core queries
  • Database context extensions for common configurations
  • Data access abstractions implementations

Key Components

Repository Implementations

  • ReadOnlyEfRepository<TDbContext, T, TKey>: Read-only repository base class
  • EfRepository<TDbContext, T, TKey>: Full repository with CRUD operations
  • Supports both tracking and no-tracking queries
  • Built-in pagination and sorting

Specification Evaluator

  • EfCoreSpecificationEvaluator<T>: Translates domain specifications to EF Core queries
  • Supports filtering, sorting, pagination, and includes
  • Optimized query generation

EF Core Extensions

  • ModelBuilderExtensions: Extension methods for model configuration
  • EntityTypeBuilderExtensions: Extension methods for entity configuration

Features

  • Repository Pattern: Generic repository with specification support
  • EF Core Integration: Seamless Entity Framework Core integration
  • Query Optimization: Efficient query generation with tracking control
  • Specification Support: Translate domain specifications to database queries
  • Pagination: Built-in pagination support
  • Performance: Support for split queries and query tags

Installation

dotnet add package AkbarAmd.SharedKernel.Infrastructure.EntityFrameworkCore

Usage Examples

Creating a Repository

public class UserRepository : EfRepository<ApplicationDbContext, User, Guid>
{
    public UserRepository(ApplicationDbContext dbContext) 
        : base(dbContext, enableTracking: false)
    {
    }

    // Custom query methods can be added here
    public async Task<User?> GetByEmailAsync(string email, CancellationToken cancellationToken = default)
    {
        return await _dbSet
            .AsNoTracking()
            .FirstOrDefaultAsync(u => u.Email == email, cancellationToken);
    }
}

Using Specifications with Repository

// Define specification
var activeUsersSpec = new CriteriaBuilder<User>()
    .Where(u => u.IsActive)
    .OrderBy(u => u.CreatedAt)
    .Take(10)
    .Build();

// Use with repository
var users = await _userRepository.GetAsync(activeUsersSpec, cancellationToken);

Repository Operations

// Add entity
var user = new User("user@example.com", "John Doe");
await _userRepository.AddAsync(user, cancellationToken);
await _userRepository.SaveChangesAsync(cancellationToken);

// Update entity
user.UpdateName("Jane Doe");
await _userRepository.UpdateAsync(user, cancellationToken);
await _userRepository.SaveChangesAsync(cancellationToken);

// Delete entity
await _userRepository.DeleteAsync(userId, cancellationToken);
await _userRepository.SaveChangesAsync(cancellationToken);

// Get by ID
var user = await _userRepository.GetByIdAsync(userId, cancellationToken);

// Get all with pagination
var paginatedResult = await _userRepository.GetPaginatedAsync(
    pageNumber: 1,
    pageSize: 10,
    cancellationToken: cancellationToken);

Configuring DbContext

public class ApplicationDbContext : DbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        
        // Apply configurations
        modelBuilder.ApplyConfigurationsFromAssembly(typeof(ApplicationDbContext).Assembly);
        
        // Configure audit properties
        modelBuilder.ConfigureAuditProperties();
    }
}

Dependencies

  • Entity Framework Core 8.0: ORM framework
  • Microsoft.AspNetCore.Authorization: Authorization support
  • Microsoft.AspNetCore.Identity.EntityFrameworkCore: Identity integration

Architecture Principles

This layer follows Clean Architecture principles:

  • Implements Domain abstractions: Provides concrete implementations for repository interfaces
  • Framework-specific: Contains EF Core-specific code
  • Isolated from Domain: Domain layer has no knowledge of this implementation
  • Testable: Can be replaced with in-memory implementations for testing

Performance Considerations

  • No-Tracking by Default: Read-only operations use AsNoTracking() for better performance
  • Split Queries: Support for split queries to avoid cartesian explosion
  • Query Tags: Support for query tags for debugging and monitoring
  • Identity Resolution: Configurable identity resolution for no-tracking queries

License

MIT License - see LICENSE file for details.

Author

Akbar Ahmadi Saray - GitHub

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 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. 
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
1.0.27 89 2/1/2026
1.0.26 685 12/3/2025
1.0.25 677 12/2/2025
1.0.24 671 12/2/2025
1.0.23 681 12/2/2025
1.0.20 586 12/1/2025
1.0.19 267 11/30/2025
1.0.18 129 11/29/2025
1.0.17 297 11/11/2025
1.0.16 283 11/11/2025

Version 1.0.26:
- Updated to support new specification fluent API (Where-first pattern)
- Compatible with AndGroup/OrGroup changes from Domain layer
- All tests updated and passing

Version 1.0.25:
- Removed IConcurrentAudit interface and all related concurrency audit functionality
- Updated ConfigureFullAuditableEntity methods to remove IConcurrentAudit constraint
- Removed ConfigureConcurrentAudit methods from EntityTypeBuilderExtensions and ModelBuilderExtensions

Version 1.0.24:
- Synchronized version with Domain and Application layers

Version 1.0.23:
- Synchronized version with Domain and Application layers

Version 1.0.19:
- Enhanced EfCoreSpecificationEvaluator with full support for nested include chains
- Added automatic handling of nullable navigation properties in ThenInclude chains
- Improved include chain evaluation with proper type resolution
- Full support for Include().ThenInclude().ThenInclude() chains in EF Core queries
- Enhanced specification pattern integration with Entity Framework Core

Version 1.0.18:
- Removed Version property configuration from ConfigureAggregateRoots method
- Updated ConfigureModificationAudit to use ModifiedAt/ModifiedBy instead of LastModifiedAt/LastModifiedBy
- Updated index names and filter expressions to reflect property name changes
- Breaking change: Entity Framework Core configurations now use ModifiedAt/ModifiedBy property names