Enigmatry.Entry.Core.EntityFramework 9.1.1-preview.4

This is a prerelease version of Enigmatry.Entry.Core.EntityFramework.
dotnet add package Enigmatry.Entry.Core.EntityFramework --version 9.1.1-preview.4
                    
NuGet\Install-Package Enigmatry.Entry.Core.EntityFramework -Version 9.1.1-preview.4
                    
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.1.1-preview.4" />
                    
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.1.1-preview.4" />
                    
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.1.1-preview.4
                    
#r "nuget: Enigmatry.Entry.Core.EntityFramework, 9.1.1-preview.4"
                    
#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.1.1-preview.4
                    
#: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.1.1-preview.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Enigmatry.Entry.Core.EntityFramework&version=9.1.1-preview.4&prerelease
                    
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.1.1-preview.4 85 6/27/2025
9.1.1-preview.3 135 6/4/2025
9.1.0 404 6/3/2025
9.0.1-preview.8 120 5/26/2025
9.0.1-preview.7 209 5/13/2025
9.0.1-preview.6 216 5/9/2025
9.0.1-preview.5 146 5/7/2025
9.0.1-preview.4 117 4/30/2025
9.0.1-preview.2 130 4/1/2025
9.0.0 1,028 2/26/2025
8.1.1-preview.3 127 5/7/2025
8.1.1-preview.1 131 4/1/2025
8.1.0 674 2/19/2025
8.0.1-preview.4 76 2/7/2025
8.0.1-preview.2 62 1/15/2025
8.0.0 1,190 11/27/2024
3.4.6-preview.10 74 11/27/2024
3.4.3 2,010 10/22/2024
3.4.2 728 10/11/2024
3.4.1 144 10/9/2024
3.4.0 144 10/9/2024
3.3.2 525 8/28/2024
3.3.2-preview.7 87 8/27/2024
3.3.1 430 7/16/2024
3.3.1-preview.4 73 7/12/2024
3.3.0 1,154 6/20/2024
3.2.1-preview.4 67 6/17/2024
3.2.1-preview.1 81 5/23/2024
3.2.0 3,901 4/3/2024
3.1.1-preview.1 1,033 3/13/2024
3.1.0 474 3/8/2024
3.1.0-preview.2 438 2/19/2024
3.0.1-preview.2 1,155 2/9/2024
3.0.1-preview.1 89 1/24/2024
3.0.0 1,234 1/15/2024
3.0.0-preview.14 119 1/9/2024
3.0.0-preview.12 85 1/9/2024
3.0.0-preview.5 79 1/10/2024
3.0.0-preview.2 146 12/28/2023
3.0.0-preview 162 12/20/2023
2.1.0 201 12/28/2023
2.0.1-preview.3 120 12/1/2023
2.0.1-preview.2 91 11/29/2023
2.0.1-preview.1 91 11/28/2023
2.0.0 477 11/8/2023
2.0.0-preview.3 456 10/27/2023
2.0.0-preview.2 98 10/27/2023
2.0.0-preview.1 91 10/27/2023
2.0.0-preview 153 10/27/2023
1.1.500 190 10/27/2023
1.1.495 236 9/24/2023
1.1.486 475 9/13/2023
1.1.484 240 9/7/2023
1.1.482 176 9/6/2023
1.1.480 329 8/24/2023
1.1.477 515 8/2/2023
1.1.464 221 7/5/2023
1.1.447 875 5/26/2023
1.1.396 322 4/11/2023
1.1.383 327 4/3/2023
1.1.377 315 3/13/2023
1.1.376 281 3/13/2023
1.1.365 1,010 2/15/2023