Nhibernateを使用するアプリがあります。これは私の最初のアプリなので、初心者です。最初のgetメソッドをテストしようとしています。
protected void Button1_Click(object sender, EventArgs e)
{
IList<Person> persons =
SessionManager
.SessionFactory
.GetCurrentSession()
.CreateCriteria(typeof(Person))
.List<Person>();
}
セッションマネージャのコードは次のとおりです。
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; }
}
}
しかし、アプリを実行してbtnをクリックするたびに。内部例外メッセージで例外をスローします。
"'name'属性が無効です-値'hibernate.current_session_context_class'は、そのデータ型'String'に従って無効です-列挙型制約が失敗しました。"}
これが私の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>
もともと、私は入れませんでした
<property name="hibernate.current_session_context_class">managed</property>
しかし、それは私にエラーを与えています:
CurrentSessionContextが構成されていません(プロパティcurrent_session_context_classを設定してください)!