NHibernate Session.Flush&驱逐vs清除 [英] NHibernate Session.Flush & Evict vs Clear

查看:92
本文介绍了NHibernate Session.Flush&驱逐vs清除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在测试中,我想保留一个对象,然后通过从数据库(而不是会话)中获取它来证明它是持久的,我发现以下内容之间没有区别:

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

// 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.

这篇关于NHibernate Session.Flush&驱逐vs清除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆