2012-05-06 4 views
0

Nhibernateを使用するアプリケーションがあります。これは私が初心者ですので、これを使用して私の最初のアプリです。私は最初のgetメソッドをテストしようとしています。'hibernate.current_session_context_class'の値は、そのデータ型 'String'によって無効です。

protected void Button1_Click(object sender, EventArgs e) 
{ 
    IList<Person> persons = 
    SessionManager 
     .SessionFactory 
     .GetCurrentSession() 
     .CreateCriteria(typeof(Person)) 
     .List<Person>(); 
} 

ここでセッションMGRコードです:

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]をクリックします。

"The 'name' attribute is invalid - The value 'hibernate.current_session_context_class' is invalid according to its datatype 'String' - The Enumeration constraint failed."}

は、ここに私の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> 

を入れていなかったが、それは私にエラーを与えている:それは、内部例外MSGと例外がスローされます:

No CurrentSessionContext configured (set the property current_session_context_class)!

答えて

0

ウェブの場合アプリケーションは、次の手順を試してください。

<property name="current_session_context_class">managed_web</property> 

Winフォームアプリケーションでは、次のことをしようとした場合:

<property name="current_session_context_class">thread_static</property> 
関連する問題