我想通过代码使用映射,所以我有一个Employee ( namespace NHibernateTests.Classes
) 类和一个EmployeeMappings ( namespace NHibernateTests.Mappings
)类
我的整个 nhibernate 配置设置在一个 xml 文件hibernate.cfg.xml
中,当前如下所示:
<?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="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">User Id=NHIBERNATE;Password=NHIBERNATE;Data Source=XE</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<mapping assembly="NHibernateTests"/>
</session-factory>
</hibernate-configuration>
这给了我运行时错误:没有持久性:NHibernateTests.Classes.Employee
我尝试(并出错)了一些mapping
元素设置,但没有运气。我阅读了如何为 hbm.xml 元素设置资源,但找不到by code
映射的答案。
namespace NHibernateTests.Classes
{
public class Employee
{
public virtual Address Address { get; set; }
public virtual string FirstName { get; set; }
public virtual int Id { get; set; }
}
}
namespace NHibernateTests.Mappings
{
public class EmployeeMappings : ClassMapping<Employee>
{
public EmployeeMappings()
{
this.Id(e => e.Id, mapper =>
{
mapper.Generator(Generators.HighLow);
});
}
}
}