2010-05-14 40 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