2010-05-14 64 views
2

我一直在试图为我的数据库表列指定一个自定义的命名约定。到目前为止,我已经能够为表格名称设置约定,但不能设置实际的列。我在网上看过一些指南,但他们没有使用最新的Fluent NHibernate(1.0.0 RTM)。帮助使用FluentNHibernate创建ColumnName约定

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? 
    } 
} 

请帮忙。

回答

4

要创建列名的约定,您应该使用IPropertyConvention而不是IComponentConvention。

例如(使用转换骆驼情况相同的方法,以强调在您的示例代码):

public class ColumnNameConvention : IPropertyConvention 
{ 
    public void Apply(IPropertyInstance instance) 
    { 
     instance.Column(instance.Property.Name.ChangeCamelCaseToUnderscore()); 
    } 
} 
+0

感谢。它工作完美。 :) – rebelliard 2010-05-14 12:17:00