StronglyTypedIds.EFConverters
1.0.0
dotnet add package StronglyTypedIds.EFConverters --version 1.0.0
NuGet\Install-Package StronglyTypedIds.EFConverters -Version 1.0.0
<PackageReference Include="StronglyTypedIds.EFConverters" Version="1.0.0" />
<PackageVersion Include="StronglyTypedIds.EFConverters" Version="1.0.0" />
<PackageReference Include="StronglyTypedIds.EFConverters" />
paket add StronglyTypedIds.EFConverters --version 1.0.0
#r "nuget: StronglyTypedIds.EFConverters, 1.0.0"
#addin nuget:?package=StronglyTypedIds.EFConverters&version=1.0.0
#tool nuget:?package=StronglyTypedIds.EFConverters&version=1.0.0
StronglyTypedIds.EFConverters
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:
- A value converter for each strongly typed ID type
- 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
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 |