标签: nhibernate-collections

NHibernate自定义集合类型

我正在调用一个实体对象,Patient并且该实体具有一个名为Visitstype 的属性VisitsCollection.

VisitsCollections是一个子类,IList<Visit>但它也为集合添加了一些自定义逻辑(如自动排序,一些验证,通知等).

需要使用自定义集合类型,因为它会将一些数据添加到添加到集合中的实体,并透明地执行其他一些文书工作.

现在我想在NHibernate中映射它,所以我创建了:

<list name="Visits" lazy="true" fetch="select">
    <key foreign-key="PatientId" />
    <index column="Timestamp" />
    <one-to-many class="Visit" not-found="ignore"/>
</list>
Run Code Online (Sandbox Code Playgroud)

我得到一个例外:

无法将'NHibernate.Collection.PersistentList'类型的对象强制转换为'... VisitsCollection'

每当我访问访问属性.

我也尝试过以这种方式映射它:

<list name="Visits" lazy="true" fetch="select" collection-type="VisitsCollection">
    <key foreign-key="PatientId" />
    <index column="Timestamp" />
    <one-to-many class="Visit" not-found="ignore"/>
</list>
Run Code Online (Sandbox Code Playgroud)

但是,我还是得到了这个例外:

自定义类型未实现UserCollectionType:..... VisitsCollection

我不想VisitsCollection从任何NHibernate类型继承我,因为集合类是我希望它与DAL无关的框架的一部分(因为它将在许多场景中使用 - 不仅仅用于数据库).

关于如何映射这个,保留我的代码结构的任何想法?

提前致谢.

collections nhibernate nhibernate-mapping nhibernate-collections

7
推荐指数
1
解决办法
5714
查看次数

Fluent-Nibernate与wpf:约会使用uNhAddIns ... ObservableListType <T>默认?

我试图使用Fluent-Nibernate和需要Observable集合的wpf(实现INotifyCollectionChanged接口).

uNHAddins:NHibernate的非官方插件我找到了

    uNhAddIns.WPF.Collections.Types.ObservableListType<T>
Run Code Online (Sandbox Code Playgroud)

实现INotifyCollectionChanged.它可以像这样在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");
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

有没有人知道如何使用Fluent-Nibernate 实现一个总是使用ObservableListType作为默认IList实现的约定?

更新:完美的解决方案可以替代Fluent-NHibernate-Automapper

collections wpf nhibernate-mapping fluent-nhibernate nhibernate-collections

3
推荐指数
1
解决办法
1530
查看次数