I have the following code in accessing a database via nhibernate:
ISessionFactory factory =
new NHibernate.Cfg.Configuration().Configure().BuildSessionFactory();
using (ISession session = factory.OpenSession())
{
ICriteria sc = session.CreateCriteria(typeof(Site));
siteList = sc.List();
session.Close();
}
factory.Close();
I wonder whether it is possible to wrap it in this way:
using (var factory= new NHibernate.Cfg.Configuration().Configure().BuildSessionFactory())
{
var session = factory.OpenSession();
ICriteria sc = session.CreateCriteria(typeof(Site));
siteList = sc.List();
}
As far as I understand, all the connection inside the using() block will be automatically closed. So I guess that the second statement is fully equivalent to the first.
Am I right?