NPv.Common.Infrastructure.Db.Ef 1.6.0

Suggested Alternatives

NPv.DataAccess.Ef

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

Simple Generic Repository Library

📦 Version 1.6.0 — Entity Enhancements & LongText Support

Brief Description

A foundational infrastructure library designed to streamline Entity Framework Core data access by providing a generic repository pattern and a pluggable unit of work abstraction. It promotes consistency, reusability, and isolation of transactional logic across services, APIs, and background workers.

🚀 Getting Started Started

To integrate this library into your project:

  • Add a reference to the package.
  • Register your DbContext and IDbContextProvider in the service container.
  • Use the provided interfaces and base types to simplify CRUD and transaction management.

✅ Quick Example

Create a custom ApplicationContext:

The following demonstrates how to create ApplicationContext:

public class ApplicationContext(DbContextOptions<ApplicationContext> options) : DbContext(options)
{
    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);      
    
        foreach (var entityType in builder.Model.GetEntityTypes()
                     .Where(t => t.ClrType.IsSubclassOf(typeof(Entity))))
        {
            var entity = builder.Entity(entityType.ClrType);
            entity.Property("Id")
                  .ValueGeneratedOnAdd()
                  .HasValueGenerator<GuidV7ValueGenerator>();
        }

        UserMapping.ApplyMapping(builder);
        //other mappings

        DefaultString256MaxLengthMapping.ApplyMapping(builder);
    }
}

🛠 Usage

When adding a new entity to the database, the Id will be automatically generated via GuidV7ValueGenerator. Default string column length is limited to 256 characters unless marked with [LongText] or [MaxLength].

📜 Changelog

2025-05-15 1.6

  • Added support for [LongText] attribute to explicitly mark nvarchar(max) fields
  • Updated DefaultString256MaxLengthMapping to ignore [LongText] properties
  • Improved string mapping conventions for EF Core

Internal refactoring and prep for model consistency analysis

2025-04-19 1.5.0

Improved PerRequestUnitOfWorkProvider with:

  • Rename to DbContextProvider : IDbContextProvider
    • Explicit CommitAsync() support
  • IsCommitted flag
  • ObjectDisposedException.ThrowIf(...) for .NET 9+
  • Internal protection against usage after commit/dispose
  • Improved compatibility with nested IServiceScope usage (manual vs automatic commit support)

2025-02-15 1.4.1-2

  • remove obsolete code
  • bugfixing
  • refactoring

2025-02-15 1.3.

  • broken version

2025-01-14 - Version 1.2.3

  • include Version 1.2.2
  • Add EFCoreGenericRepository, IUnitOfWorkProvider, PerRequestUnitOfWorkProvider
  • Marked as [Obsolete]: PerRequestDbContextProvider, IDbContextProvider, ConsoleDbContextProvider, EfGenericRepository

2024-12-12 - Version 1.2.1

Add GuidV7ValueGenerator

2024-11-18 - Version 1.2.0

  • Update to .Net 9
  • Update dependencies
  • Correct adding README.md

2024-11-12 - Version 1.1.0

  • Add README file
  • Update to .Net 8

🔐 License

This project is licensed under the MIT License.

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.