I have an app that uses Nhibernate. This is my first app using it so I am newbie. I am trying to test my first get method.
protected void Button1_Click(object sender, EventArgs e)
{
IList<Person> persons =
SessionManager
.SessionFactory
.GetCurrentSession()
.CreateCriteria(typeof(Person))
.List<Person>();
}
Here's the session mgr code:
public static partial class SessionManager
{
private static readonly ISessionFactory _sessionFactory;
static SessionManager()
{
Configuration cfg = new Configuration().Configure();
_sessionFactory =
Fluently
.Configure(cfg)
.Mappings(m => m.FluentMappings.AddFromAssembly(typeof(SessionManager).Assembly))
.BuildSessionFactory();
//CurrentSessionContext.Bind(_sessionFactory.GetCurrentSession());
}
public static ISession OpenSession()
{
return _sessionFactory.OpenSession();
}
public static ISessionFactory SessionFactory
{
get { return _sessionFactory; }
}
}
But everytime I run the app and click the btn. it throws an exception with inner exception msg:
"The 'name' attribute is invalid - The value 'hibernate.current_session_context_class' is invalid according to its datatype 'String' - The Enumeration constraint failed."}
Here's my hibernate.cfg.xml
<?xml version="1.0" encoding="utf-16"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="hibernate.current_session_context_class">managed</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Server=localhost\MSSQLSERVERR2;Database=PersonSearch;Trusted_Connection=True</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="cache.use_minimal_puts">false</property>
<property name="use_outer_join">false</property>
</session-factory>
</hibernate-configuration>
Originally, I did not put
<property name="hibernate.current_session_context_class">managed</property>
but it is giving me an error:
No CurrentSessionContext configured (set the property current_session_context_class)!