Enigmatry.Entry.Core.EntityFramework 9.2.0

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

Core EntityFramework Library

This library provides extension methods and utilities for Entity Framework Core, focusing on querying and data seeding.

Intended Usage

Use this library when you need additional query capabilities with Entity Framework Core, such as entity not found handling, mapping query results, and pagination support.

Installation

Add the package to your project:

dotnet add package Enigmatry.Entry.Core.EntityFramework

Usage Examples

Using Query Extensions

using Enigmatry.Entry.Core.EntityFramework;
using Enigmatry.Entry.Core.Entities;
using Enigmatry.Entry.Core.Paging;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;

// Sample entity class
public class Product 
{
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public decimal Price { get; set; }
    public bool IsAvailable { get; set; }
}

public class ProductDto
{
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public decimal Price { get; set; }
}

public class ProductService
{
    private readonly DbContext _dbContext;
    private readonly IMapper _mapper;
    
    public ProductService(DbContext dbContext, IMapper mapper)
    {
        _dbContext = dbContext;
        _mapper = mapper;
    }
    
    // Find a product by ID, throw exception if not found
    public async Task<Product> GetProductById(int id)
    {
        return await _dbContext.Set<Product>()
            .Where(p => p.Id == id)
            .SingleOrNotFoundAsync();
    }

    // Map a single entity to a DTO
    public async Task<ProductDto> GetProductDtoById(int id)
    {
        return await _dbContext.Set<Product>()
            .Where(p => p.Id == id)
            .SingleOrDefaultMappedAsync<Product, ProductDto>(_mapper);
    }
    
    // Map a collection of entities to DTOs
    public async Task<List<ProductDto>> GetAvailableProductDtos()
    {
        return await _dbContext.Set<Product>()
            .Where(p => p.IsAvailable)
            .ToListMappedAsync<Product, ProductDto>(_mapper);
    }
    
    // Get a paged response of products
    public async Task<PagedResponse<Product>> GetPagedProducts(int pageNumber, int pageSize)
    {
        var request = new PagedRequest
        {
            PageNumber = pageNumber,
            PageSize = pageSize,
            SortBy = "Name",
            SortDirection = "asc"
        };
        
        return await _dbContext.Set<Product>()
            .Where(p => p.IsAvailable)
            .ToPagedResponseAsync(request);
    }
}

Required Dependencies

This library builds on Entity Framework Core and has the following dependencies:

  1. Entity Framework Core
  2. System.Linq.Dynamic.Core - For dynamic sorting
  3. AutoMapper - For mapping entities to DTOs

Dependency Injection Example

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using AutoMapper;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // Register DbContext
        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            
        // Register AutoMapper (required for mapping extensions)
        services.AddAutoMapper(typeof(Startup).Assembly);
    }
}

Using the Seeding Interface

using Enigmatry.Entry.Core.EntityFramework.Seeding;
using Microsoft.EntityFrameworkCore;

// Create a seeder class
public class ProductSeeder : ISeeding
{
    public void Seed(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Product>().HasData(
            new Product 
            { 
                Id = 1, 
                Name = "Product 1", 
                Price = 19.99m, 
                IsAvailable = true 
            },
            new Product 
            { 
                Id = 2, 
                Name = "Product 2", 
                Price = 29.99m, 
                IsAvailable = true 
            },
            new Product 
            { 
                Id = 3, 
                Name = "Product 3", 
                Price = 39.99m, 
                IsAvailable = false 
            }
        );
    }
}

// Use the seeder in your DbContext
public class ApplicationDbContext : DbContext
{
    public DbSet<Product> Products { get; set; } = default!;
    
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }
    
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        
        // Apply the seeder
        new ProductSeeder().Seed(modelBuilder);
    }
}
Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Enigmatry.Entry.Core.EntityFramework:

Package Downloads
Enigmatry.Entry.EntityFramework

Building Block for adding EntityFramework related infrastructure to an Entry based project

Enigmatry.Entry.SmartEnums.EntityFramework

Building Block for support of SmartEnums with EntityFramework in an Entry based project

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.3.1-preview.1 276 11/25/2025
9.3.0 378 11/10/2025
9.2.0 1,102 9/24/2025
9.1.1-preview.5 191 8/8/2025
9.1.1-preview.4 111 6/27/2025
9.1.1-preview.3 181 6/4/2025
9.1.0 1,168 6/3/2025
9.0.1-preview.8 140 5/26/2025
9.0.1-preview.7 228 5/13/2025
9.0.1-preview.6 389 5/9/2025
9.0.1-preview.5 165 5/7/2025
9.0.1-preview.4 143 4/30/2025
9.0.1-preview.2 147 4/1/2025
9.0.0 1,499 2/26/2025
8.2.0 535 9/24/2025
8.1.1-preview.3 145 5/7/2025
8.1.1-preview.1 151 4/1/2025
8.1.0 1,134 2/19/2025
8.0.1-preview.4 93 2/7/2025
8.0.1-preview.2 77 1/15/2025
8.0.0 1,270 11/27/2024
3.4.6-preview.10 91 11/27/2024
3.4.3 2,154 10/22/2024
3.4.2 823 10/11/2024
3.4.1 216 10/9/2024
3.4.0 221 10/9/2024
3.3.2 608 8/28/2024
3.3.2-preview.7 102 8/27/2024
3.3.1 508 7/16/2024
3.3.1-preview.4 92 7/12/2024
3.3.0 1,230 6/20/2024
3.2.1-preview.4 85 6/17/2024
3.2.1-preview.1 107 5/23/2024
3.2.0 3,974 4/3/2024
3.1.1-preview.1 1,048 3/13/2024
3.1.0 542 3/8/2024
3.1.0-preview.2 459 2/19/2024
3.0.1-preview.2 1,170 2/9/2024
3.0.1-preview.1 103 1/24/2024
3.0.0 1,306 1/15/2024
3.0.0-preview.14 136 1/9/2024
3.0.0-preview.12 101 1/9/2024
3.0.0-preview.5 93 1/10/2024
3.0.0-preview.2 166 12/28/2023
3.0.0-preview 207 12/20/2023
2.1.0 284 12/28/2023
2.0.1-preview.3 137 12/1/2023
2.0.1-preview.2 111 11/29/2023
2.0.1-preview.1 108 11/28/2023
2.0.0 543 11/8/2023
2.0.0-preview.3 474 10/27/2023
2.0.0-preview.2 118 10/27/2023
2.0.0-preview.1 109 10/27/2023
2.0.0-preview 204 10/27/2023
1.1.500 258 10/27/2023
1.1.495 305 9/24/2023
1.1.486 537 9/13/2023
1.1.484 314 9/7/2023
1.1.482 254 9/6/2023
1.1.480 418 8/24/2023
1.1.477 592 8/2/2023
1.1.464 309 7/5/2023
1.1.447 974 5/26/2023
1.1.396 420 4/11/2023
1.1.383 423 4/3/2023
1.1.377 411 3/13/2023
1.1.376 379 3/13/2023
1.1.365 1,115 2/15/2023