NHibernate:拦截器返回值的含义

发布于 2024-07-19 08:52:47 字数 1209 浏览 2 评论 0原文

我认为这是一个简单的问题,但我的谷歌搜索对此很弱。

我遇到了以下链接中描述的关于生成的 ID 和级联的问题:

https://www.hibernate.org/hib_docs/nhibernate/html/example-parentchild.html(向底部)

我使用他们建议的拦截器方法修复了它。 一切似乎都很顺利,所以我很高兴。

也就是说,我不知道以下方法的返回值的意义是什么:

    public override bool OnLoad(object entity, object id, object[] state, string[] propertyNames, IType[] types)
    {
        if (entity is Persistent) ((Persistent)entity).OnLoad();
        return false;
    }

    public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types)
    {
        if (entity is Persistent) ((Persistent)entity).OnSave();
        return false;
    }

在这两种情况下都返回 false。

当我在 google 上搜索 NHibernate 拦截器时,我看到了很多如何编写拦截器的示例。 有些则返回 true (http://www.lostechies.com/blogs/rhouston/archive/2008/03/27/creating-a-timestamp-interceptor-in-nhibernate.aspx)。 我不知道这里有什么区别。 我的代码正在运行,但拦截器对我来说似乎很有用,所以我想有更好的理解。

I think this is an easy question, but my googling is weak on this.

I had the problem described in the following link with regard to a generated ID and cascading:

https://www.hibernate.org/hib_docs/nhibernate/html/example-parentchild.html (towards the bottom)

I fixed it using their suggested method of an Interceptor. Everything appears to be working, so I am happy.

That said, I have no idea what the significance of the return value is from methods such as:

    public override bool OnLoad(object entity, object id, object[] state, string[] propertyNames, IType[] types)
    {
        if (entity is Persistent) ((Persistent)entity).OnLoad();
        return false;
    }

    public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types)
    {
        if (entity is Persistent) ((Persistent)entity).OnSave();
        return false;
    }

In both cases false is returned.

When I google about NHibernate Interceptors I see plenty of examples of how to write one. Some instead return true (http://www.lostechies.com/blogs/rhouston/archive/2008/03/27/creating-a-timestamp-interceptor-in-nhibernate.aspx). I have no idea what the difference is here. My code is working, but Interceptors seem useful to me so I'd like to have a better understanding.

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

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

发布评论

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

评论(2

白首有我共你 2024-07-26 08:52:47

我相信返回值应该指示拦截器方法中状态参数是否已更改。 你是对的——现在用谷歌搜索是一件很困难的事——NHibernate 网站最近搬迁了,谷歌似乎找不到像以前那样多的有用信息。

I believe the return value should indicate if the state parameter has been changed in the interceptor method. You're right - it's a tough one to google at the moment - the NHibernate site moved recently and google doesn't seem to find as much useful info as it used to.

你怎么这么可爱啊 2024-07-26 08:52:47

Huey,

阅读这篇文章,我不是 .net 程序员,但这篇文章非常有用:

http://knol.google.com/k/fabio-maulo/nhibernate-chapter-11/1nr4enxv3dpeq/14#

第 11 章拦截器和事件 It
对于应用程序来说通常很有用
对发生的某些事件做出反应
NHibernate 内部。 这允许
实施某些类型的
通用功能和扩展
NHibernate 功能。

11.1。 拦截器 IInterceptor 接口提供了来自拦截器的回调
与应用程序的会话允许
检查申请和/或
操纵持久化的属性
对象在保存、更新之前,
删除或加载。 一种可能的用途
因为这是为了跟踪审计
信息。 例如,
自动跟随IInterceptor
设置 createTimestamp 当
IAuditable 已创建并更新
lastUpdateTimestamp 属性
IAuditable 已更新。

希望它能给你更多启发。

Huey,

Read this post, i'm not a .net programmer, but this post is very usefull:

http://knol.google.com/k/fabio-maulo/nhibernate-chapter-11/1nr4enxv3dpeq/14#

Chapter 11. Interceptors and events It
is often useful for the application to
react to certain events that occur
inside NHibernate. This allows
implementation of certain kinds of
generic functionality, and extension
of NHibernate functionality.

11.1. Interceptors The IInterceptor interface provides callbacks from the
session to the application allowing
the application to inspect and/or
manipulate properties of a persistent
object before it is saved, updated,
deleted or loaded. One possible use
for this is to track auditing
information. For example, the
following IInterceptor automatically
sets the createTimestamp when an
IAuditable is created and updates the
lastUpdateTimestamp property when an
IAuditable is updated.

Hope it enlight you a little more.

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