Help in creating ColumnName convention using FluentNHibernate
I was trying to specify a custom naming convention for the columns of a database table. So far, I've managed to set up a convention for the table name, but not the actual columns. I've seen several tutorials on the internet, but they don't work 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 source to share
1 answer
To create a column naming convention, you must use IPropertyConvention , not IComponentConvention.
For example (using the same method for converting camel case to emphasize as in your example code):
public class ColumnNameConvention : IPropertyConvention
{
public void Apply(IPropertyInstance instance)
{
instance.Column(instance.Property.Name.ChangeCamelCaseToUnderscore());
}
}
+4
a source to share