0

这是我的域类:

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

我不明白为什么。

请帮忙。

4

1 回答 1

1

您的实体的任何 C# 属性都必须声明为virtual。以这种方式更改您的课程:

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; }
}
于 2012-12-24T11:09:43.367 回答