Enigmatry.Entry.Core.EntityFramework 9.3.0

dotnet add package Enigmatry.Entry.Core.EntityFramework --version 9.3.0
                    
NuGet\Install-Package Enigmatry.Entry.Core.EntityFramework -Version 9.3.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.3.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.3.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.3.0
                    
#r "nuget: Enigmatry.Entry.Core.EntityFramework, 9.3.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.3.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.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Enigmatry.Entry.Core.EntityFramework&version=9.3.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.0 289 11/10/2025
9.2.0 847 9/24/2025
9.1.1-preview.5 188 8/8/2025
9.1.1-preview.4 105 6/27/2025
9.1.1-preview.3 174 6/4/2025
9.1.0 1,132 6/3/2025
9.0.1-preview.8 134 5/26/2025
9.0.1-preview.7 224 5/13/2025
9.0.1-preview.6 386 5/9/2025
9.0.1-preview.5 164 5/7/2025
9.0.1-preview.4 135 4/30/2025
9.0.1-preview.2 145 4/1/2025
9.0.0 1,484 2/26/2025
8.2.0 407 9/24/2025
8.1.1-preview.3 143 5/7/2025
8.1.1-preview.1 145 4/1/2025
8.1.0 1,118 2/19/2025
8.0.1-preview.4 88 2/7/2025
8.0.1-preview.2 75 1/15/2025
8.0.0 1,263 11/27/2024
3.4.6-preview.10 88 11/27/2024
3.4.3 2,149 10/22/2024
3.4.2 816 10/11/2024
3.4.1 208 10/9/2024
3.4.0 212 10/9/2024
3.3.2 601 8/28/2024
3.3.2-preview.7 101 8/27/2024
3.3.1 498 7/16/2024
3.3.1-preview.4 88 7/12/2024
3.3.0 1,224 6/20/2024
3.2.1-preview.4 79 6/17/2024
3.2.1-preview.1 102 5/23/2024
3.2.0 3,968 4/3/2024
3.1.1-preview.1 1,045 3/13/2024
3.1.0 534 3/8/2024
3.1.0-preview.2 452 2/19/2024
3.0.1-preview.2 1,166 2/9/2024
3.0.1-preview.1 103 1/24/2024
3.0.0 1,299 1/15/2024
3.0.0-preview.14 128 1/9/2024
3.0.0-preview.12 97 1/9/2024
3.0.0-preview.5 91 1/10/2024
3.0.0-preview.2 161 12/28/2023
3.0.0-preview 203 12/20/2023
2.1.0 275 12/28/2023
2.0.1-preview.3 136 12/1/2023
2.0.1-preview.2 107 11/29/2023
2.0.1-preview.1 105 11/28/2023
2.0.0 537 11/8/2023
2.0.0-preview.3 470 10/27/2023
2.0.0-preview.2 115 10/27/2023
2.0.0-preview.1 107 10/27/2023
2.0.0-preview 201 10/27/2023
1.1.500 257 10/27/2023
1.1.495 303 9/24/2023
1.1.486 532 9/13/2023
1.1.484 311 9/7/2023
1.1.482 251 9/6/2023
1.1.480 413 8/24/2023
1.1.477 589 8/2/2023
1.1.464 303 7/5/2023
1.1.447 966 5/26/2023
1.1.396 410 4/11/2023
1.1.383 417 4/3/2023
1.1.377 401 3/13/2023
1.1.376 372 3/13/2023
1.1.365 1,107 2/15/2023