In a test where I want to persist an object and then prove it was persisted by fetching it from the db (and not the session), I notice no difference between the following:
// save it
session.Clear()
// fetch it
or
// save it
session.Flush()
session.Evict(_instance)
// fetch it
The lazy programmer in me leans towards one line over two. Is there some reason I am missing to favor the two lines more?
Flushing synchronizes the persistent store with in-memory changes but not vice-versa. Note that for all NHibernate ADO.NET connections/transactions, the transaction isolation level for that connection applies to all operations executed by NHibernate!
NHibernate will evict associated entities automatically if the association is mapped with cascade="all" or cascade="all-delete-orphan". The ISession also provides a Contains() method to determine if an instance belongs to the session cache. To completely evict all objects from the session cache, call ISession. Clear().
NHibernate is an open source object-relational mapper, or simply put, a way to rapidly retrieve data from your database into standard . NET objects. This article teaches you how to create NHibernate sessions, which use database sessions to retrieve and store data into the database.
session.Clear actually cancels all pending saves/updates/etc.
If it doesn't, it's because you're using identity so the entity is persisted without flushing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With