[英]Fluent-Nibernate with wpf: Convention to use uNhAddIns…ObservableListType<T> as default?
I am trying to use Fluent-Nibernate with wpf that require Observable collections (implement the INotifyCollectionChanged
interface). 我试图使用Fluent-Nibernate和需要Observable集合的wpf(实现INotifyCollectionChanged
接口)。
At uNHAddins: Unofficial addins for NHibernate i found the 在uNHAddins:NHibernate的非官方插件我找到了
uNhAddIns.WPF.Collections.Types.ObservableListType<T>
that implements INotifyCollectionChanged
. 实现INotifyCollectionChanged
。 It can be configured in Fluent-Nibernate like this 它可以像这样在Fluent-Nibernate中配置
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 anybody know how to implement a Convention with Fluent-Nibernate that always uses ObservableListType as default IList implementation ? 有没有人知道如何使用Fluent-Nibernate 实现一个总是使用ObservableListType作为默认IList实现的约定?
Update: The perfect solution would be something that does the replacement with Fluent-NHibernate-Automapper 更新:完美的解决方案可以替代Fluent-NHibernate-Automapper
Something like this should do the trick: 像这样的东西应该做的伎俩:
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);
}
}
In response to the question update: 回答问题更新:
This convention should work with the automapper like so: 这个约定应该适用于automapper,如下所示:
AutoMap.AssemblyOf<Store>(cfg)
.Conventions.Add<ObservableListConvention>();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.