NHibernate - 无法编译映射文件

时间:2012-12-24 09:13:43

标签: nhibernate nhibernate-mapping

这是我的域类:

public class User
{
    public Guid id { get; set; }

    public string firstName { get; set; }

    public string lastName { get; set; }

    public string mailAddress { get; set; }
}

这是我的映射文件:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Test" namespace="Test.model">

  <class name="User" >
    <id name="id">
      <generator class="guid"/>
    </id>
    <property name="firstName"  />
    <property name="lastName" />
    <property name="mailAddress" />
  </class>

</hibernate-mapping>

这是我的hibernate-cfg文件:

<?xml version="1.0" encoding="utf-8" ?>

  

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MySQLDialect</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.connection_string">Server=localhost;Database=vbook;User ID=root;Password=ziben</property>
<!--<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>-->

<property name="hbm2ddl.auto">update</property>
<property name="generate_statistics">true</property>
<property name="show_sql">true</property>


<mapping file="data/mapping/User.hbm.xml" />

这是我创建会话工厂的方式:

 var configuration = new Configuration();
 configuration.Configure();

 _sessionFactory = configuration.BuildSessionFactory();

我收到以下异常: 无法编译映射文档:data / mapping / User.hbm.xml

我无法理解为什么。

请帮助。

1 个答案:

答案 0 :(得分:1)

您实体的任何C#属性必须声明为虚拟。以这种方式改变你的课程:

public class User
{
    public virtual Guid id { get; set; }
    public virtual string firstName { get; set; }
    public virtual string lastName { get; set; }
    public virtual string mailAddress { get; set; }
}