PosInformatique.Foundations.EntityFramework.Converters
1.5.0
Prefix Reserved
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
<PackageReference Include="PosInformatique.Foundations.EntityFramework.Converters" Version="1.5.0" />
<PackageVersion Include="PosInformatique.Foundations.EntityFramework.Converters" Version="1.5.0" />
<PackageReference Include="PosInformatique.Foundations.EntityFramework.Converters" />
paket add PosInformatique.Foundations.EntityFramework.Converters --version 1.5.0
#r "nuget: PosInformatique.Foundations.EntityFramework.Converters, 1.5.0"
#:package PosInformatique.Foundations.EntityFramework.Converters@1.5.0
#addin nuget:?package=PosInformatique.Foundations.EntityFramework.Converters&version=1.5.0
#tool nuget:?package=PosInformatique.Foundations.EntityFramework.Converters&version=1.5.0
PosInformatique.Foundations.EntityFramework.Converters
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 forPropertyBuilder<DateTime>andPropertyBuilder<DateTime?>. It assumes persisted values already represent UTC and sets theirDateTime.KindtoUtc; it does not convert the time.EnumToBooleanConverter<TEnum>: aValueConverterto map an enumeration with only two values to aboolcolumn.
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 setsDateTime.KindtoUtcwhen values are read from or written to the database.- Supports both
PropertyBuilder<DateTime>andPropertyBuilder<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 aboolcolumn (and vice versa). - The
TEnumtype must be an enumeration containing exactly two distinct values, one that can be represented as0(false) and one that can be represented as1(true). - An
ArgumentException(wrapped in aTypeInitializationException) is thrown when accessing theInstanceproperty 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);
}
}
Links
| Product | Versions 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. |
-
net10.0
- Microsoft.EntityFrameworkCore (>= 10.0.0)
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.0)
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.0)
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.