0

We have convention to turn snake-case db columns to pascal case in our entities:

        Map(x => x.ProjectName).Column("project_name");

The mapping is always exactly this. How can we tell FNH to do the work rather than typing them all?

Daniel Williams
  • 8,912
  • 15
  • 68
  • 107

1 Answers1

0

implement IPropertyConvention and use

// in Apply (maybe filter out some special cases)
instance.Column(ToSnakeCase(instance.Name));


private string ToSnakeCase(string name)
{
    var result = new Stringbuilder(name.Length);
    for (int i = 0; i < name.Length; i++)
    {
        if (i > 0 && char.IsUpper(name[i]))
            result.Append('_').Append(char.ToLower(name[i]));
        else
            result.Append(char.ToLower(name[i]));
    }
    return result.ToString();
}
Firo
  • 30,626
  • 4
  • 55
  • 94