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
<PackageReference Include="E13.Common.Data.Db" Version="2025.117.22" />
<PackageVersion Include="E13.Common.Data.Db" Version="2025.117.22" />
<PackageReference Include="E13.Common.Data.Db" />
paket add E13.Common.Data.Db --version 2025.117.22
#r "nuget: E13.Common.Data.Db, 2025.117.22"
#:package E13.Common.Data.Db@2025.117.22
#addin nuget:?package=E13.Common.Data.Db&version=2025.117.22
#tool nuget:?package=E13.Common.Data.Db&version=2025.117.22
E13.Common.Data.Db
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:
Set the connection string environment variable:
$env:DESIGN_CONTEXT = "Server=127.0.0.1;Database=MyDb;User Id=sa;Password=P@ssword!;"Create a migration:
dotnet ef migrations add InitialCreate --project MyProjectUpdate the database:
dotnet ef database update --project MyProject
Dependencies
- .NET 9.0
- Microsoft.EntityFrameworkCore
- Microsoft.EntityFrameworkCore.SqlServer
- Microsoft.Extensions.Logging
Related Packages
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 | Versions 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. |
-
net9.0
- E13.Common.Core (>= 2025.114.21)
- E13.Common.Data (>= 2025.114.21)
- E13.Common.Domain (>= 2025.114.21)
- Microsoft.EntityFrameworkCore (>= 9.0.3)
- Microsoft.EntityFrameworkCore.SqlServer (>= 9.0.3)
- Microsoft.Extensions.Logging (>= 9.0.3)
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 |