How to use ObservableCollection with Fluent nHibernate?

£可爱£侵袭症+ 提交于 2019-12-10 18:59:15

问题


ObservableCollection<ItemPedido> Items

But now in Fluent nHibernate i don´t know how to use it. Is there an easy way to use ObservableCollection with Fluent nHibernate? I noticed there is a DLL NHibernate.Collection.Observable;

But i don´t know how to replace my current code that uses IList:

    public virtual IList<ItemPedido> Items
    {
        get { return _Items; }
        set { _Items = value; OnPropertyChanged(System.Reflection.MethodBase.GetCurrentMethod().Name.Substring(4)); /*OnPropertyChanged("Items");*/ }
    } private IList<ItemPedido> _Items;

how to change the above code to make it work with Observable Collection and Fluent nHibernate?


回答1:


Keep on using ObservableCollection<T> as implementation of IList<T> - no need to change the business code.

All you have to do is configure NHibernate to replace the IList<T> internally with an NhibernateObservableCollection when doing the lazy loading.

I used

uNhAddIns.WPF.Collections.Types.ObservableListType<T>

from Unofficial NHibernate Addins (unhaddins) for this.

But probaly any other implementation of NhibernateObservableCollection will do as well.

At fluent-nibernate-with-wpf-convention-to-use-unhaddins-observablelisttypet-as-Default you find the example i used to configure the ObservableCollection with Fluent nHibernate.

Note if you want to use uNhAddIns.WPF.Collections.Types.ObservableListType<T>: There is no binary distribution for this so you have to compile uNhAddIns.WPF.dll yourself from c# sourcecode.




回答2:


You can use the code from this article - http://www.codeproject.com/KB/WPF/WpfNhibernateToolkit.aspx , or you can add a custom data view and wrap your Items property into another one like it's done here - http://www.shawnduggan.com/?p=46 and http://www.shawnduggan.com/?p=84 .



来源:https://stackoverflow.com/questions/5220920/how-to-use-observablecollection-with-fluent-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!