I have the following code:
public class A
{
private ISessionFactory _sf;
A(ISessionFactory sf)
{
_sf = sf;
}
public void SomeFunc()
{
using (var session = _sf.OpenSession())
using (var transaction = session.BeginTransaction())
{
transaction.commit();
}
}
}
Used as follows in unit test
_session.CreateCriteria ...
var objectA = new A(_sessionFactory);
objectA.SomeFunc();
var someVal = _session.CreateCriteria ...
Assert.That(someVal, Is.EqualTo(someOtherValue));
I am testing a sqlite database . In my tests, I make some changes to db to properly configure it. Then I call SomeFunc (). He makes the necessary changes. As soon as I return to my test, the session, however, will not receive the updated values. It still returns the value as it was before the SomeFunc () function call. I have to execute _session.Clear () so that the changes are reflected in my assertion in the test.
Why is this needed?
Edit: cache.use_second_level_cache and cache.use_query_cache are set to false
Edit2 . Read the following instructions in the NH Documentation .
ISession SQL, ADO.NET . , ,
* from some invocations of Find() or Enumerable()
* from NHibernate.ITransaction.Commit()
* from ISession.Flush()
10.1 :
, (). .
, ? , . UniqueResult() List() db , ?
, , , ?