NHibernate拦截器/用于延迟加载集合的钩子/级联 [英] NHibernate interceptor / hook for Lazy-Loaded collections / Cascade
问题描述
最近我已经足够创建ViewModel样板代码,因此我最终在基于DynamicProxy的解决方案中添加了NotifyPropertyChanged-function.
Lately I have had about enough of creating ViewModel boilerplate code, so I ended up adding the NotifyPropertyChanged-functionality to a DynamicProxy-based solution.
为了使WPF的所有Changenotification机制都可用于我的实现,我现在要做的就是将我的Collection与ObservableCollections进行交换,不幸的是,这带来了性能问题(每条添加/删除的记录的更改通知,因此不适合大量使用,因为UI太忙于跟上更改列表).
In order to have all of WPF's Changenotification mechanisms working for my implementation, all I have to do now is exchange my Collections with ObservableCollections, which unfortunately brings along a performance issue (change notification for every record added / removed, so not fit for bulk usage because UI gets way too busy trying to keep up with the list of changes).
因此,在我的模型中,其他模型(具有HasMany关系)的集合不保存在列表中,而是包含在具有两个方法SuspendCollectionChangeNotification
和ResumeCollectionChangeNotification
的ObservableCollection派生类中(有点像实现显示在此处).
Thus, In my models, collections of other models (HasMany relationships, that is) are not held within a list, but within a ObservableCollection-derivate that has two Methods SuspendCollectionChangeNotification
and ResumeCollectionChangeNotification
(A bit like the implementation shown here).
所有基础结构都已存在,现在我正在寻找一个Interceptor钩子,该钩子使我能够在NHibernate加载Child数据之前调用Suspend()
,并在完成它之后调用Resume()
.
The infrastructure is all there, now I'm looking for an Interceptor hook that enables me to call Suspend()
before NHibernate Loads Child data and Resume()
after it's done.
我有点担心最终将其添加到我上面提到的代理中,该代理可以很好地掌握所请求的属性,但是将其保留在NHibernate Interceptor中将是很可爱的.
I'm a bit afraid I will end up adding this to the proxy I mentioned above, which has a good grasp of the properties that are being requested, but it would be just lovely to keep this in an NHibernate Interceptor...
推荐答案
NHibernate具有IInitializeCollectionEventListener
,可在加载集合时为您提供InitializeCollectionEvent
.
NHibernate has IInitializeCollectionEventListener
which gives you InitializeCollectionEvent
when it is loading a collection.
您可以像这样连接:
var listener = new YourCollectionListenerImpl();
configuration.SetListener(ListenerType.LoadCollection, adapter);
不幸的是,这仅告诉您正在加载集合.我认为无法确定何时开始和何时结束.
Unfortunately this only tells you that collection loading is taking place. I don't think it is possible to determine when it is starting and when it has finished.
这篇关于NHibernate拦截器/用于延迟加载集合的钩子/级联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!