How to use ObservableCollection with Fluent nHibernate?
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("Item开发者_Go百科s");*/ }
} private IList<ItemPedido> _Items;
how to change the above code to make it work with Observable Collection and Fluent nHibernate?
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.
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 .
精彩评论