如何映射NHibernate自定义集合与fluentNHibernate? [英] How to map NHibernate custom collection with fluentNHibernate?

查看:124
本文介绍了如何映射NHibernate自定义集合与fluentNHibernate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图映射集合两天没有成功。我也读过所有可能的文章和论坛,但仍然在那里。好,这里是问题:

I am trying to map the collection for two days without success. I also read all possible articles and forums but still down there. Ok, here is the problem:

1)集合类包含一个私有字段_internalCollection,它与NHib映射。

1) The collection class contains a private field "_internalCollection" which is mapped with NHib.

2)控制实体应该通过readonly属性公开集合。

2) The holding entity should expose the collection trough readonly property.

3)我想避免实现NHibernate接口IUserCollectionType !!!

3) I want to avoid implementing NHibernate interface IUserCollectionType!!!

我用xml映射这样做,它的工作伟大。 WarehouseEntity是一个集合Item。仓库是OrgEntity类中的只读属性。

I did this with xml mapping and it work great. The WarehouseEntity is a collection Item. Warehouses is a readonly property in OrgEntity class.

  <component name="Warehouses" class="Core.Domain.Collections.EntitySet`1[Core.Domain.OrgStructure.IWarehouseEntity,Core],Core">
    <set name="_internalCollection" table="`WAREHOUSE`" cascade="save-update" access="field" generic="true" lazy="true" >
      <key column="`WarehouseOrgId`" foreign-key="FK_OrgWarehouse" />
      <!--This is used to set the type of the collection items-->
      <one-to-many class="Domain.Model.OrgStructure.WarehouseEntity,Domain"/>
    </set>
  </component>

任何想法如何用流利的NHibernate来做?

Any idea how can I do it with fluent NHibernate?

编辑:Core.Domain.Collections.EntitySet`1是基本集合类。

Core.Domain.Collections.EntitySet`1 is base collection class. It provides basic functionality for working with collections and can fit any class which is IEntity interface.

推荐答案

尝试:

HasMany(x => x.Warehouses)
    .AsSet().KeyColumn("WarehouseOrgId")
    .Access.CamelCaseField(Prefix.Underscore)
    .ForeignKeyConstraintName("FK_OrgWarehouse");

编辑:我错过了问题的关键部分,所以这里是另一个尝试:

I missed a key part of the question so here's another try:

Component(x => x.Warehouses, m =>
    {
        m.HasMany<Warehouse>(Reveal.Member<EntitySet<IWarehouseEntity>>("_internalCollection")
           .AsSet().KeyColumn("WarehouseOrgId")
           .ForeignKeyConstraintName("FK_OrgWarehouse");
    });

我相信这不是它,但希望它把你放在正确的路径。 href =http://wiki.fluentnhibernate.org/Fluent_mapping =nofollow noreferrer> ComponentMap 。

I'm sure that's not it but hopefully it puts you on the right path. Also have a look using ComponentMap.

我的建议是避免自定义集合我替换了我们所有的扩展方法在 IEnumerable< T>

My advice is to avoid custom collections entirely. I replaced all of ours with extension methods on IEnumerable<T>.

这篇关于如何映射NHibernate自定义集合与fluentNHibernate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆