title: NHibernate how to avoid session is closed
body: <p>I can not figure out why im getting session is closed when calling the second query in my class. </p>
  
  <p>First i call the method, getPoliceData() 
  I runs fine 
  After that im calling GetSkadeData()
  and it throw the error:</p>
  
  <p>the DbFactory  class looks like this </p>
  
  <pre><code>class DbFactory
  {
      private static Lazy&lt;ISessionFactory&gt; factory = new Lazy&lt;ISessionFactory&gt;(GetSessionFactory, System.Threading.LazyThreadSafetyMode.ExecutionAndPublication);
  
      public DbFactory()
      {
  
  
  
      }
      public List&lt;PoliceData&gt; getPoliceData()  {
      using (ISession session = OpenSession())
          {
              IList&lt;PoliceData&gt; pols = session.Query&lt;PoliceData&gt;().Where(p =&gt; p.policyNumber == 053126703).ToList();
  
           return pols.ToList();
          }
  
      }
  
      public List&lt;SkadeData&gt; getSkadeData()
      {
          using (ISession session = OpenSession())
          {
              IList&lt;SkadeData&gt; skader = session.Query&lt;SkadeData&gt;().Where(p =&gt; p.Postnr == "7700").ToList();
  
              return skader.ToList();
          }
  
      }
  
  
  
      private static ISession OpenSession()
      {
          return factory.Value.GetCurrentSession();
      }
  
      private static ISessionFactory GetSessionFactory()
      {
          //NHibernate.Cfg.Configuration
          var c = new Configuration();
          //c.Configure();
          c.DataBaseIntegration(db =&gt;
          {
              db.ConnectionString = "Server=\"localhost\";database=testdb;Integrated Security=SSPI";
              db.Dialect&lt;NHibernate.Dialect.MsSql2012Dialect&gt;();
  
          });
          //c.Configure("c:\XML.xml");
  
          ModelMapper maps = new ModelMapper();
          maps.AddMapping&lt;PoliceDataMap&gt;();
          maps.AddMapping&lt;SkadeDataMap&gt;();
          c.AddMapping(maps.CompileMappingForAllExplicitlyAddedEntities());
          c.CurrentSessionContext&lt;NHibernate.Context.ThreadLocalSessionContext&gt;();
          //c.Configure().Configure();
          var sessionFac = c.BuildSessionFactory();
          return sessionFac;
  
          //return sessionFac.GetCurrentSession();
  
      }
  
  }
  </code></pre>
  
  <p>When I call the method from another class I am doing this </p>
  
  <pre><code>List&lt;PoliceData&gt; test = new List&lt;PoliceData&gt;();
  List&lt;SkadeData&gt; skader = new List&lt;SkadeData&gt;();
  DbFactory poli = new DbFactory();
  test = poli.getPoliceData();
  skader = poli.getSkadeData();
  </code></pre>
  
  <p>Do I need to create a new  instance of dbfactory or is it posible to use the same session for two different querys. 
  It would be nice if the Nhibernate just got confured once and after that you just open and closed session when needed. </p>