本文介绍了Fluent-Nibernate with wpf:约定使用uNhAddIns ... ObservableListType< T>作为默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Fluent-Nibernate与需要观察集合(实现 INotifyCollectionChanged 接口)的wpf。



在中找到

  uNhAddIns.WPF.Collections.Types.ObservableListType< T>实现 INotifyCollectionChanged 

。它可以像这样在Fluent-Nibernate中配置

 命名空间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);
}
}
}

有人知道如何执行 ObservableListType作为默认IList实现的Fluent-Nibernate实现



更新:完美的解决方案是用Fluent-NHibernate-Automapper替换的东西

解决方案

这样的东西应该能做到:

  public class ObservableListConvention:
IHasManyConvention,IHasManyToManyConvention,ICollectionConvention {

//一对多关系
public void Apply(IOneToManyCollectionInstance instance){

ApplyObservableListConvention(instance);
}

//多对多关系
public void Apply(IManyToManyCollectionInstance instance){

ApplyObservableListConvention(instance);
}

//用于组件或简单类型的集合
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);
}
}

/ strong>



此约定应与自动整理程序一起使用,如下所示:

  AutoMap.AssemblyOf< Store>(cfg)
.Conventions.Add< ObservableListConvention>();


I am trying to use Fluent-Nibernate with wpf that require Observable collections (implement the INotifyCollectionChanged interface).

At uNHAddins: Unofficial addins for NHibernate i found the

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

that implements INotifyCollectionChanged. It can be configured in Fluent-Nibernate like this

    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 ?

Update: The perfect solution would be something that does the replacement with 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:

AutoMap.AssemblyOf<Store>(cfg)
  .Conventions.Add<ObservableListConvention>();

这篇关于Fluent-Nibernate with wpf:约定使用uNhAddIns ... ObservableListType&lt; T&gt;作为默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 07:15