79381858

Date: 2025-01-23 16:34:38
Score: 0.5
Natty:
Report link

In this article from 2023 explans how to achive exactly that for all types.

Using the override on ConfigureConventions and from the received ModelConfigurationBuilder then you can achieve that:

public class RiderConverter() : ValueConverter<EquineBeast, string> 
(
    v => v.ToString(),
    v => (EquineBeast)Enum.Parse(typeof(EquineBeast), v));
);

protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
    configurationBuilder
        .Properties<Rider>()
        .HaveConversion<RiderConverter>();
}

This is will also allow to specify other properties like Types, max lengths, requireds... etc!

Reasons:
  • Blacklisted phrase (1): this article
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Pautx