迭代 IPersistentCollection 项目
我正在监听 NHibernate 中的审核事件,特别是 OnPostUpdateCollection(PostCollectionUpdateEvent @event)
我想迭代 @event.Collection
元素。
@event.Collection 是一个 IPersistenCollection
,它没有实现 IEnumerable
。有一个 Entries
方法返回一个 IEnumerable
,但它需要一个 ICollectionPersister
,我不知道在哪里可以得到它。
此处已提出问题: http://osdir.com/ml/nhuusers /2010-02/msg00472.html,但没有确凿的答案。
I am listening to audit events in NHibernate, specifically to OnPostUpdateCollection(PostCollectionUpdateEvent @event)
I want to iterate through the @event.Collection
elements.
The @event.Collection is an IPersistenCollection
which does not implements IEnumerable
. There is the Entries
method that returns an IEnumerable
, but it requires an ICollectionPersister
which I have no idea where I can get one.
The questions is already asked here: http://osdir.com/ml/nhusers/2010-02/msg00472.html, but there was no conclusive answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Pedro,
搜索 NHibernate 代码我可以找到以下关于 IPercientCollection (@event.Collection) 的 GetValue 方法的文档:
这样,我们可以得出结论,您可以将集合转换为 IEnumerable,并且一切都会正常工作。
我已经构建了一个映射包的小示例,事情就在这里:
希望这会有所帮助!
菲利佩
Pedro,
Searching NHibernate code I could found the following doc about GetValue method of IPersistentCollection (@event.Collection):
With that, we can conclude that you can cast your collection to an IEnumerable and things will work fine.
I've built a little sample mapping a bag and things got like that over here:
Hope this helps!
Filipe
如果您需要对集合执行更复杂的操作,您可能需要集合持久化器,您实际上可以通过以下扩展方法获得它(本质上,您需要通过 AbstractCollectionEvent 来解决可见性问题)。 GetLoadedCollectionPersister 方法):
希望有帮助!
最好的问候,
奥利弗·哈纳皮
If you need to do more complex operations with the collection, you are probably going to need the collection persister, which you can actually get with the following extension method (essentially, you need to work around the visibility by of the
AbstractCollectionEvent.GetLoadedCollectionPersister
method):Hope it helps!
Best Regards,
Oliver Hanappi