我不明白为什么 NHibernate 会这样做。
这是我在 MS SQL 中的表的一部分
CREATE TABLE Person (
nameFamily text,
nameGiven text
)
这是 Person.hbm.xml
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Infosci.Dpd.Model.Person,Infosci.Dpd.Model" table="Person" lazy="true">
<property type="string" name="NameGiven" column="nameGiven" />
<property type="string" name="NameFamily" column="nameFamily" />
</class>
</hibernate>
在我的 Person.cs 中,我将我的属性命名如下
string NameFamily
{
get ;
set ;
}
string NameGiven
{
get ;
set ;
}
然后我尝试使用以下代码创建记录
ISession session = NHibernateHelper.GetCurrentSession();
Person person = new Person();
person.NameFamily = "lee";
session.Save(person);
奇怪的是,当我尝试执行它时,NHibernate 实际上通过执行以下操作来更改列名
NHibernate: INSERT INTO Person (name_family,name_given.......
因此,NHibernate 在这里将我的列名从 NameFamily 更改为 name_family,尽管我确实指定了列名。
这是 NHibernate 错误吗?或者我需要做任何配置吗?
这是我的休眠配置文件
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=xxxxxxx;Initial Catalog=xx;Integrated Security=True;Pooling=False;User ID=xxxx;Password=xxxx</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
这就是我创建 sessionFactory 的方式
sessionFactory = new `Configuration().Configure("hibernate.cfg.xml").
SetNamingStrategy(ImprovedNamingStrategy.Instance).
AddFile("Person.hbm.xml").
BuildSessionFactory();`