PosInformatique.Foundations.EntityFramework.Converters 1.5.0

Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package PosInformatique.Foundations.EntityFramework.Converters --version 1.5.0
                    
NuGet\Install-Package PosInformatique.Foundations.EntityFramework.Converters -Version 1.5.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="PosInformatique.Foundations.EntityFramework.Converters" Version="1.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PosInformatique.Foundations.EntityFramework.Converters" Version="1.5.0" />
                    
Directory.Packages.props
<PackageReference Include="PosInformatique.Foundations.EntityFramework.Converters" />
                    
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 PosInformatique.Foundations.EntityFramework.Converters --version 1.5.0
                    
#r "nuget: PosInformatique.Foundations.EntityFramework.Converters, 1.5.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 PosInformatique.Foundations.EntityFramework.Converters@1.5.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=PosInformatique.Foundations.EntityFramework.Converters&version=1.5.0
                    
Install as a Cake Addin
#tool nuget:?package=PosInformatique.Foundations.EntityFramework.Converters&version=1.5.0
                    
Install as a Cake Tool

PosInformatique.Foundations.EntityFramework.Converters

NuGet version NuGet downloads

Introduction

Provides a collection of basic Entity Framework Core value converters and extension methods to simplify common property configuration scenarios.

The converters and configuration extensions currently available are:

  • AssumeUtc(): an extension method for PropertyBuilder<DateTime> and PropertyBuilder<DateTime?>. It assumes persisted values already represent UTC and sets their DateTime.Kind to Utc; it does not convert the time.
  • EnumToBooleanConverter<TEnum>: a ValueConverter to map an enumeration with only two values to a bool column.

More converters will be added in future versions of this package.

Install

You can install the package from NuGet:

dotnet add package PosInformatique.Foundations.EntityFramework.Converters

Available converters

Assume UTC for a DateTime property

  • AssumeUtc() assumes values in the database already represent UTC and sets DateTime.Kind to Utc when values are read from or written to the database.
  • Supports both PropertyBuilder<DateTime> and PropertyBuilder<DateTime?>.
⚠️ Important: this does not convert times to UTC

The AssumeUtc() method does not convert a value between time zones or change its clock time. It only sets the DateTime.Kind to DateTimeKind.Utc (using DateTime.SpecifyKind) when the value is read from or written to the database.

SQL Server datetime/datetime2 columns do not store any time zone information, and Entity Framework Core returns DateTime values with DateTimeKind.Unspecified by default, which can lead to ambiguous or incorrect behavior when comparing or serializing dates (for example with System.Text.Json, which treats Unspecified dates differently than Utc dates).

Use this extension only when the DateTime values persisted in your datetime/datetime2 SQL Server columns already represent UTC. If the database stores local (non-UTC) times, convert them to UTC yourself before using this extension; otherwise, they will be labeled UTC without being converted.

Examples
Example: Assume a DateTime property contains UTC values
using Microsoft.EntityFrameworkCore;

public class OrderConfiguration : IEntityTypeConfiguration<Order>
{
    public void Configure(EntityTypeBuilder<Order> builder)
    {
        builder.Property(o => o.CreatedAt)
            .AssumeUtc();
    }
}
Example: Assume a nullable DateTime property contains UTC values
builder.Property(o => o.ShippedAt)
    .AssumeUtc();

Enum to boolean

  • Provides the EnumToBooleanConverter<TEnum> value converter to map an enumeration to a bool column (and vice versa).
  • The TEnum type must be an enumeration containing exactly two distinct values, one that can be represented as 0 (false) and one that can be represented as 1 (true).
  • An ArgumentException (wrapped in a TypeInitializationException) is thrown when accessing the Instance property if the enumeration does not comply with this constraint.
Examples
Example: Configure an enum property as a boolean column
using Microsoft.EntityFrameworkCore;

public enum OrderStatus
{
    Pending = 0,
    Completed = 1,
}

public class OrderConfiguration : IEntityTypeConfiguration<Order>
{
    public void Configure(EntityTypeBuilder<Order> builder)
    {
        builder.Property(o => o.Status)
            .HasConversion(EnumToBooleanConverter<OrderStatus>.Instance);
    }
}
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
1.6.0-rc.1 0 11/17/2026
1.5.0 94 11/10/2026
1.5.0-rc.1 56 11/10/2026
1.4.0 92 11/9/2026
1.4.0-rc.5 59 11/7/2026
1.4.0-rc.4 109 10/24/2026
1.4.0-rc.3 99 10/14/2026
1.4.0-rc.2 87 10/6/2026

1.4.0
 - Initial release with the support Entity Framework converters for UTC DateTime and enum to boolean persistence.