I have a question about the getting started sample for NHibernate. It was my impression that an ISession should stay open for a unit of work. The ProductRepository in the getting started example shows that each CRUD method opens a new ISession, starts a Transaction, then commits it and closes the ISession?
Code:
public Product GetByName(string name)
{
using (ISession session = NHibernateHelper.OpenSession())
{
Product product = session
.CreateCriteria(typeof(Product))
.Add(Restrictions.Eq("Name", name))
.UniqueResult<Product>();
return product;
}
}
What happens if the product object has a lazy loaded associated class like Orders? Would fetching the Orders collection cause an error on this object because the ISession it is connected to is closed?
Am I missing something?