Fluent-Nibernate with wpf: convention on using uNhAddIns ... ObservableListType <T> by default?
I am trying to use Fluent-Nibernate with wpf that require Observable collections (implement an interface INotifyCollectionChanged).
At uNHAddins: Unofficial add-ons for NHibernate I found
uNhAddIns.WPF.Collections.Types.ObservableListType<T>
which implements INotifyCollectionChanged. It can be configured in Fluent-Nibernate as follows
namespace FluentNHibernateTutorial.Mappings
{
public class StoreMap : ClassMap<Store>
{
public StoreMap()
{
Id(x => x.Id);
Map(x => x.Name);
HasManyToMany(x => x.Products)
.CollectionType<uNhAddIns.WPF.Collections.Types
.ObservableListType<Product>>()
.Cascade.All()
.Table("StoreProduct");
}
}
}
Does anyone know how to implement the Fluent-Nibernate Convention, which always uses ObservableListType as the default implementation of IList ?
Update: The ideal solution would be to replace Fluent-NHibernate-Automapper
+3
1
- :
public class ObservableListConvention :
IHasManyConvention, IHasManyToManyConvention, ICollectionConvention {
// For one-to-many relations
public void Apply(IOneToManyCollectionInstance instance) {
ApplyObservableListConvention(instance);
}
// For many-to-many relations
public void Apply(IManyToManyCollectionInstance instance) {
ApplyObservableListConvention(instance);
}
// For collections of components or simple types
public void Apply(ICollectionInstance instance) {
ApplyObservableListConvention(instance);
}
private void ApplyObservableListConvention(ICollectionInstance instance) {
Type collectionType =
typeof(uNhAddIns.WPF.Collections.Types.ObservableListType<>)
.MakeGenericType(instance.ChildType);
instance.CollectionType(collectionType);
}
}
:
automapper :
AutoMap.AssemblyOf<Store>(cfg)
.Conventions.Add<ObservableListConvention>();
+7