Short and sweet:
Should I always flush a
SessionScope
before making any native SQL query in my application?I guess the answer is 'yes' because NHibernate implements caching, so maybe changes made are still not in the DB so the query would get inconsistent results.
How is the correct way to make those queries in the same transaction of the current active one in NHibernate?
This is important because I could get deadlocks in my business logic.
Further documentation about both questions would be appreciated too!
(I assumed that by "flushing" you're mentioning
ISession.Flush()
):ISession.CreateSQLQuery()
. Other is to use NHibernateITransaction.Enlist()
. However, I'm not sure if executing a DbCommand usingEnlist()
will flush the session.