Friends, I have the following problem, when compiling my application it returns me the
following error: No session bound to the current context. I use NhibernateHelper, and
the error appears in this line of code:
public static ISession GetSessao() { return Instance.GetSessionFactory().GetCurrentSession(); } Como posso resolver esse erro?
Segue meu código completo:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using NHibernate.Mapping.Attributes; using NHibernate.Cfg; using NHibernate; using System.IO; using NHibernate.Context; namespace SDPJDominio.DataAccess { public class NhibernateHelper { private ISessionFactory sessionFactory; public static ISession GetSessao() { return Instance.GetSessionFactory().GetCurrentSession(); } public static ISessionFactory Teste() { MemoryStream stream = new System.IO.MemoryStream(); HbmSerializer.Default.Validate = true; HbmSerializer.Default.Serialize(stream, System.Reflection.Assembly.GetExecutingAssembly()); stream.Position = 0; Configuration configuration= new Configuration(); configuration.Configure(); configuration.SetProperty("connection.connection_string", ConfigNhibernate.getConfig()); configuration.SetProperty("current_session_context_class", "thread_static"); configuration.AddInputStream(stream); stream.Close(); Instance.sessionFactory = configuration.BuildSessionFactory(); return Instance.sessionFactory; } public NhibernateHelper() { MemoryStream stream = new System.IO.MemoryStream(); HbmSerializer.Default.Validate = true; HbmSerializer.Default.Serialize(stream, System.Reflection.Assembly.GetExecutingAssembly()); stream.Position = 0; Configuration configuration= new Configuration(); configuration.Configure(); configuration.SetProperty("connection.connection_string", ConfigNhibernate.getConfig()); configuration.AddInputStream(stream); stream.Close(); sessionFactory = configuration.BuildSessionFactory(); } public static ISessionFactory SessionFactory { get { return Instance.sessionFactory; } } private ISessionFactory GetSessionFactory() { return sessionFactory; } public static NhibernateHelper Instancia { get { returnCreateSessionKey.gerenciadorDeSessao; } } public static ISession OpeningSession() { return Instance.GetSessionFactory().OpenSession(); } public static void ReloadSession(object obj) { CurrentSession.Refresh(obj); } public static ISession ReloadSession { get { return Instance.GetSessionFactory().GetCurrentSession(); } } class CreateSessionKey { internal static readonly NhibernateHelper SESSIONMANAGER= new NhibernateHelper(); } } } Could you kindly help me?