避免 NHibernate 中实体的一级缓存?

发布于 2024-09-11 22:14:55 字数 147 浏览 3 评论 0原文

我有一个在外部更新的实体(使用触发器、存储过程)。这意味着实体可以在同一会话中在我不知情的情况下进行更改,并且我需要始终执行数据库命中,并且从不使用一级缓存中的实体。

使用NHibernate(或者实际上是Castle ActiveRecord)可以实现这一点吗?

I have an entity which is updated externally (using triggers, stored procedures). This means the entity can change without my knowledge in the same session, and it is required for me that I always perform a database hit, and never use the entity from the first level cache.

Is this possible using NHibernate (or actually, Castle ActiveRecord)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇柔作态 2024-09-18 22:14:55

您可以使用 IStatelessSession 而不是 ISession 来禁用一级缓存:

using (ISessionFactory sf = cfg.BuildSessionFactory())
using (IStatelessSession session = sf.OpenStatelessSession())
{
    // ...
}

You cold use a IStatelessSession instead of ISession to disable first level cache:

using (ISessionFactory sf = cfg.BuildSessionFactory())
using (IStatelessSession session = sf.OpenStatelessSession())
{
    // ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文