2012-12-24 46 views
0

這是我的域類:NHibernate的 - 不能編譯映射文件

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> 

這是我的休眠,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(); 

我得到以下異常: 無法編譯映射文件:數據/製圖/ User.hbm.xml

我不明白爲什麼。

請幫忙。

+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; } 
}