开发者

NHibernate Session.Flush & Evict vs Clear

开发者 https://www.devze.com 2022-12-30 09:20 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消