NHibernate:拦截器返回值的含义
我认为这是一个简单的问题,但我的谷歌搜索对此很弱。
我遇到了以下链接中描述的关于生成的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信返回值应该指示拦截器方法中状态参数是否已更改。 你是对的——现在用谷歌搜索是一件很困难的事——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.
Huey,
阅读这篇文章,我不是 .net 程序员,但这篇文章非常有用:
http://knol.google.com/k/fabio-maulo/nhibernate-chapter-11/1nr4enxv3dpeq/14#
希望它能给你更多启发。
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#
Hope it enlight you a little more.