StronglyTypedIds.EFConverters 1.0.0

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

StronglyTypedIds.EFConverters

NuGet

EF Core value converters for strongly typed IDs, automatically generated at compile time.

Description

StronglyTypedIds.EFConverters is a source generator that automatically creates Entity Framework Core value converters for your strongly typed ID types. It eliminates the need to manually write converters for each ID type, making your EF Core integration cleaner and more maintainable.

Installation

// Via .NET CLI
dotnet add package StronglyTypedIds.EFConverters

// Via Package Manager
Install-Package StronglyTypedIds.EFConverters

Usage

1. Define your strongly typed ID

First, ensure your strongly typed ID has the StronglyTypedIdAttribute or appropriate generated code attribute:

[StronglyTypedId(Template.Int)]
public partial struct UserId{}

2. Configure EF Core to use the generated converters

In your DbContext configuration, simply call the extension method:

protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
    base.ConfigureConventions(configurationBuilder);
    
    // This will register all your strongly typed ID converters
    configurationBuilder.UseStronglyTypedIdConverters();
}

3. Use your strongly typed IDs in entity models

public class User
{
    public UserId Id { get; set; }
    public string Name { get; set; }
    // Other properties...
}

EF Core will now seamlessly convert between your strongly typed ID and its underlying value when reading from or writing to the database.

How It Works

The source generator scans your project and referenced assemblies for types marked with StronglyTypedIdAttribute and automatically generates:

  1. A value converter for each strongly typed ID type
  2. An extension method for easy registration with EF Core

This happens at compile time, so there's no runtime performance penalty.

Requirements

  • .NET Standard 2.0 or later
  • Entity Framework Core

License

MIT

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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.0.0 161 3/22/2025