JorgeCostaMacia.ValueObject.EfConverter 6.0.4

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

JorgeCostaMacia.ValueObject.EfConverter

Native EF Core value converters for JorgeCostaMacia.ValueObject value objects — one converter per family (value object <-> underlying value), applied explicitly per property. Provider-agnostic (works with Npgsql, SQL Server, SQLite, …).

NuGet Downloads Build License


Install

dotnet add package JorgeCostaMacia.ValueObject.EfConverter

Brings JorgeCostaMacia.ValueObject and Microsoft.EntityFrameworkCore (the provider-agnostic core — not a database provider). Your own provider (e.g. Npgsql.EntityFrameworkCore.PostgreSQL) builds on the same core, so there is no conflict; NuGet resolves EF Core to your provider's version.

Usage

Apply a converter

using JorgeCostaMacia.ValueObject.EfConverter.Infrastructure;

builder.Property(e => e.Email).HasConversion(new StringValueObjectConverter<Email>());

One converter per family — IntValueObjectConverter<>, StringValueObjectConverter<>, DecimalValueObjectConverter<>, … — closed over your concrete value object. Map each property explicitly: it keeps the mapped surface intentional (a transient value object never gets persisted by accident) and the column type under your control. Multi-field value objects (ranges) are not single-column and are not covered here.

The same converter serves required and nullable properties (Email and Email?): EF maps a null reference to a NULL column and only invokes the converter for non-null values. For a nullable property, pass the converter type.HasConversion(typeof(StringValueObjectConverter<Email>)) — to avoid a nullable-reference warning (CS8620) on the instance overload.

Value object as a primary key

A value object works as a key via its converter (complex/owned types cannot be keys). Configure it explicitly, since a converted key is app-assigned:

builder.HasKey(e => e.Id);
builder.Property(e => e.Id)
    .HasConversion(new IntValueObjectConverter<UserId>())
    .ValueGeneratedNever();

Notes

  • Rehydration goes through the value object's constructor (found by reflection, compiled once) — not the Create factory — so reads do not re-run domain validation on already-persisted data. The constructor may be non-public.
  • Querying by the underlying value uses the value object's conversion operator, e.g. where (int)e.Id > 1000 or where ((string)e.Name).StartsWith("a").
  • byte[]-backed value objects (ByteValueObject): byte[] is a mutable reference type, so EF Core needs a ValueComparer to detect changes by content rather than by reference. Value objects are immutable (you replace the whole object, which EF sees as a new reference), so this only matters if you mutate the array in place — an anti-pattern. If you do, configure a comparer on that property.

About

Part of shared-net.

Author: Jorge Costa Maciá — GitHub

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  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 is compatible.  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.

Version Downloads Last Updated
6.0.4 89 7/22/2026
6.0.3 86 7/22/2026
6.0.2 90 7/19/2026
6.0.1 101 7/15/2026
6.0.0 90 7/13/2026
5.0.0 99 7/12/2026
4.3.0 95 7/12/2026
4.2.0 96 7/11/2026
4.1.0 95 7/10/2026
4.0.0 104 7/9/2026
3.0.1 97 7/8/2026