views:

59

answers:

1

I've been trying to specify a custom naming convention for my database table columns. So far, I have been able to setup a convention for the table's name, but not the actual columns. I've seen a few guides on the internet, but they're not working using the latest Fluent NHibernate (1.0.0 RTM).

public class CamelCaseSplitNamingConvention : IClassConvention, IComponentConvention
{
    public void Apply(IClassInstance instance)
    {
        instance.Table(instance.EntityType.Name.ChangeCamelCaseToUnderscore());
    }

    public void Apply(IComponentInstance instance)
    {
        // is this the correct call for columns? If not, which one?
    }
}

Please help.

+2  A: 

To create a convention for column names you should use an IPropertyConvention rather than an IComponentConvention.

For example (using the same method to convert camel case to underscore as in your example code):

public class ColumnNameConvention : IPropertyConvention
{
    public void Apply(IPropertyInstance instance)
    {
        instance.Column(instance.Property.Name.ChangeCamelCaseToUnderscore());
    }
}
Erik Öjebo
Thanks. It worked perfectly. :)
Rafael Belliard