NHibernate Session.Flush & Evict vs Clear
In a test where I want to persist an object and then prove it was persisted 开发者_如何学Cby 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?
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.
精彩评论