nhibernate INamingStrategy -在columnName之前添加className

本文关键字:添加 className columnName INamingStrategy nhibernate | 更新日期: 2023-09-27 18:14:54

我想在ID列之前添加className。为例。我有一个类,

public class Employer {
    public long ID {get;set;}
  }

和May map文件,

 <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" ... >
  <class name="Employer" >
    <id name="ID">
      <generator class="sequence"  >
        <param name="sequence">Employer_Seq</param>
      </generator>
    </id>
</hibernate-mapping>

在INamingStrategy中,有一个方法可以改变属性名,

 public string PropertyToColumnName(string propertyName)
        {
            propertyName =Up(DefaultNamingStrategy.Instance.PropertyToColumnName(propertyName));
            return propertyName;
        }

我应该怎么做改变ID到EMPLOYER_ID而不定义它在hbm.xml文件?在方法中我没有className信息

nhibernate INamingStrategy -在columnName之前添加className

你可以试试这样做:

DefaultNamingStrategy.Instance.LogicalColumnName(columnName, propertyName);