I am trying to connect to nHibernate but I did not do that. I have a configuration file which is look like below
<?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>
and have a config file load method like below
//create instance for 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
My mapping file
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);
}
}
When get data by this method _session.Get(id);
The error has been occurred
An exception of type 'NHibernate.HibernateException' occurred in NHibernate.dll but was not handled in user code
Additional information: Unable to locate persister for the entity named 'EMS.Domain.Hrm.Entities.Employee'.
Please give me any idea that will appreciate.