我正在尝试连接到nHibernate,但我没有这样做。我有一个配置文件,如下所示
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.connection_string_name">EMS</property>
<property name="show_sql">false</property>
<property name="generate_statistics">true</property>
<property name="current_session_context_class">thread_static</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
<property name="cache.use_second_level_cache">false</property>
<property name="cache.use_query_cache">false</property>
<property name="default_schema">EMS.dbo</property>
<property name="adonet.batch_size">200</property>
<mapping assembly="EMS.Infra.Data"/>
</session-factory>
</hibernate-configuration>
并有一个如下所示的配置文件加载方法
//为cfg创建实例
configuration = new Configuration(); // read config default style
configuration.AddAssembly(Assembly.GetCallingAssembly());//forcely add mapping assembly
//add fluent auto mapping and conventions
Fluently.Configure(configuration).Mappings(m =>
m.FluentMappings.AddFromAssemblyOf<Employee>().Conventions.Add(
PrimaryKey.Name.Is(x => "Id"),
ForeignKey.EndsWith("Id")));
//add dialect and connections strting
configuration.SessionFactory().Integrate.Using<MsSql2012Dialect>().Connected.ByAppConfing("EMS");//EMS is the connection name
我的映射文件
public class EmployeeMap : ClassMap<Employee>
{
public EmployeeMap()
{
Table("HRM.Employee");
Id(x => x.Id).GeneratedBy.Identity().UnsavedValue(0);
Map(x => x.LocationId);
Map(x => x.SalutationId);
Map(x => x.FirstName);
Map(x => x.MiddleName);
Map(x => x.LastName);
Map(x => x.NickName);
Map(x => x.EmpName);
}
}
通过此方法获取数据时 _session.Get(ID);
发生了错误
发生了'NHibernate.HibernateException'类型的异常 NHibernate.dll但未在用户代码中处理
其他信息:无法找到实体的持久性 名为'EMS.Domain.Hrm.Entities.Employee'。
请给我任何可以欣赏的想法。