开发者

Help creating a ColumnName Convention using FluentNHibernate

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.


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());
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜