NHibernateSessionManager.Instance.GetSessionFrom(SessionFactoryConfigPath).Flush();
i get
null id in FoodOrder.Core.Entities.Articles entry (don't flush the Session after an exception occurs)
can i just use try catch and session.Close or what is better to do in this example?
example
public void CommitChanges()
{
if (NHibernateSessionManager.Instance.HasOpenTransactionOn(SessionFactoryConfigPath))
{
NHibernateSessionManager.Instance.CommitTransactionOn(SessionFactoryConfigPath);
}
else
{
try
{
// If there's no transaction, just flush the changes
NHibernateSessionManager.Instance.GetSessionFrom(SessionFactoryConfigPath).Flush();
}
finally
{
NHibernateSessionManager.Instance.GetSessionFrom(SessionFactoryConfigPath).Close();
}
}
}
After an exception, your session is in an invalid state and should just be disposed. This is one reason why you should always perform writes in a transaction. If not, you have no idea as to the state of your database. So I would recommend that:
Hope that helps.