© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•17mo ago•
2 replies
CEO da CloudFlare

Generic converter bounding in EF Core

Is there an way to "easily" define converters for all properties which uses an generic type? Currently, I have something like this:

protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
    configurationBuilder.Properties<EntityId<User>>().HaveConversion<EntityIdValueConverter<User>>();
    configurationBuilder.Properties<EntityId<Tenant>>().HaveConversion<EntityIdValueConverter<Tenant>>();
}
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
    configurationBuilder.Properties<EntityId<User>>().HaveConversion<EntityIdValueConverter<User>>();
    configurationBuilder.Properties<EntityId<Tenant>>().HaveConversion<EntityIdValueConverter<Tenant>>();
}


and an ugly static method that gets all properties from entities, map eachs one and applies the converter using reflection and activator.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Generic entity type in EF Core
C#CC# / help
4y ago
EF Core - Generic repository update method
C#CC# / help
4y ago
❔ EF Core setting property with value converter to null
C#CC# / help
3y ago
EF Core
C#CC# / help
2y ago