E13.Common.Data.Db 2025.117.22

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

E13.Common.Data.Db

NuGet Version License: MIT

Overview

E13.Common.Data.Db is a package within the E13.Common collection designed for database access using Entity Framework Core. It provides a foundation for implementing the data access layer in a layered application architecture, with built-in support for common database operations and entity tracking.

Features

  • Base DbContext: Extended DbContext with automatic entity tracking
  • Repository Pattern: Generic repository implementation for consistent data access
  • Entity Tracking: Automatic tracking of entity creation, modification, and deletion
  • Soft Delete: Built-in support for soft delete functionality
  • Design-Time Factory: Support for EF Core migrations and design-time context creation
  • Query Filters: Global query filters for entity types

Installation

dotnet add package E13.Common.Data.Db

Usage

Creating a Database Context

using E13.Common.Data.Db;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;

public class MyDbContext : BaseDbContext
{
    public DbSet<Customer> Customers => Set<Customer>();
    public DbSet<Order> Orders => Set<Order>();
    
    public MyDbContext(DbContextOptions options, ILogger<MyDbContext> logger)
        : base(options, logger)
    {
    }
    
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        // Configure your entity mappings
        
        base.OnModelCreating(modelBuilder);
    }
}

Using the Repository Pattern

// Define a repository for a specific entity
public class CustomerRepository : Repository<MyDbContext, Customer>
{
    public CustomerRepository(MyDbContext dbContext) : base(dbContext)
    {
    }
    
    // Add custom repository methods
    public IEnumerable<Customer> GetPremiumCustomers()
    {
        return GetAll(c => c.IsPremium);
    }
}

// Using the repository
var repository = new CustomerRepository(dbContext);
var customer = new Customer { Name = "John Doe" };
repository.Insert(customer);
dbContext.SaveChanges("admin", "CustomerService");

Design-Time Factory for Migrations

public class MyDbContextFactory : DesignTimeDbContextFactory<MyDbContext>
{
    // The base class implementation will use the DESIGN_CONTEXT environment variable
    // for the connection string when running migrations
}

Database Migrations

To work with migrations:

  1. Set the connection string environment variable:

    $env:DESIGN_CONTEXT = "Server=127.0.0.1;Database=MyDb;User Id=sa;Password=P@ssword!;"
    
  2. Create a migration:

    dotnet ef migrations add InitialCreate --project MyProject
    
  3. Update the database:

    dotnet ef database update --project MyProject
    

Dependencies

  • .NET 9.0
  • Microsoft.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore.SqlServer
  • Microsoft.Extensions.Logging

E13.Common.Data.Db is part of the E13.Common collection, which includes:

  • E13.Common.Core - Core utilities and base classes
  • E13.Common.Domain - Domain layer components
  • E13.Common.Api - Web API layer components
  • E13.Common.AspNet - ASP.NET shared components
  • E13.Common.Blazor - Blazor UI components

Contributing

Contributions to E13.Common.Data.Db are welcome. If you have suggestions or improvements, please submit an issue or create a pull request in the GitHub repository.

License

This project is licensed under the MIT License. For more details, see the LICENSE file in the repository.

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 (1)

Showing the top 1 NuGet packages that depend on E13.Common.Data.Db:

Package Downloads
E13.Common.Api

Common package for defining an Api layer for a webapi project

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2025.117.22 189 4/27/2025
2025.114.21 249 4/24/2025
2025.114.20 278 4/24/2025
2025.114.18 293 4/24/2025
2025.112.17 262 4/22/2025
2025.112.16 266 4/22/2025
2025.111.15 274 4/21/2025
2025.106.14 279 4/16/2025
2025.106.12 322 4/16/2025
2025.97.11 312 4/7/2025
2025.96.9 259 4/6/2025
2025.96.8 260 4/6/2025
2025.91.7 284 4/1/2025
2025.91.6 282 4/1/2025
2025.90.4 274 3/31/2025
2023.30.1 499 1/30/2023
2023.18.1 450 1/18/2023
2021.327.1 6,637 11/23/2021
2021.324.4 1,237 11/20/2021
1.0.0 257 4/1/2025
Loading failed