NHibernate的:我如何多发性父母的一种常见类型的儿童映射到一个单一的表? [英] NHibernate: How do I map mutiple parents' children of a common type into a single table?

查看:117
本文介绍了NHibernate的:我如何多发性父母的一种常见类型的儿童映射到一个单一的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法让NHibernate的让我存储在多个ChildObjectTable但ChildObjects指他们带回不同ParentObjects?或者,我必须创建一个单独的ChildObject类/表中的每个ParentObject类型?



我煮下来到下面,我想对这些对象的映射

 公共类ParentObjectA 
{
公共虚拟Int64的标识{搞定;私人集; }

公共虚拟的IDictionary< INT,ChildObject>儿童{搞定;私人集; }
}

公共类ParentObjectB
{
公共虚拟Int64的标识{搞定;私人集; }

公共虚拟的IDictionary< INT,ChildObject>儿童{搞定;私人集; }
}

公共类ChildObject
{
公共虚拟Int64的标识{搞定;私人集; }
}



成如下的表结构:

  ParentObjectTableA 
标识BIGINT

ParentObjectTableB
标识BIGINT

ChildObjectTable
ID BIGINT
的ParentId BIGINT
ParentQualifier VARCHAR(50)


解决方案

下面的地图似乎从对象的角度工作。我不使用crosstables的想法过于激烈,但我觉得这可能比试图处理继承的清洁剂。我要去看看该选项,以及和我会在这里发布我的调查结果完成的缘故。 。ParentObjectA的欢迎评论



映射

 <地图名称= 孩子们表=ParentAxChildObject> 
<键列=的ParentId/>
<索引列=ChildObjectNumberTYPE =的Int32/>
<许多对多类=ChildObject/>
< /图>



ParentObjectB映射

 <地图名称=儿童表=ParentBxChildObject> 
<键列=的ParentId/>
<索引列=ChildObjectNumberTYPE =的Int32/>
<许多对多类=ChildObject/>
< /图>



这些生成以下交叉表:

  ParentAxChildObject 
[的ParentId] [BIGINT] NOT NULL,
[ELT] [BIGINT] NOT NULL,
[ChildObjectNumber] [INT] NOT NULL,

ParentBxChildObject
[的ParentId] [BIGINT] NOT NULL,
[ELT] [BIGINT] NOT NULL,
[ChildObjectNumber] [INT] NOT NULL,


Is there any way to get NHibernate to let me store multiple ChildObjects in the ChildObjectTable but refer them back to different ParentObjects? Or do I have to create a separate ChildObject class/table for each ParentObject type?

I've boiled this down to the following, I'm trying to map these objects:

public class ParentObjectA
{
    public virtual Int64 Id { get; private set; }

    public virtual IDictionary<int, ChildObject> Children { get; private set; }
}

public class ParentObjectB
{
    public virtual Int64 Id { get; private set; }

    public virtual IDictionary<int, ChildObject> Children { get; private set; }
}

public class ChildObject
{
    public virtual Int64 Id { get; private set; }   
}

into the following table structure:

ParentObjectTableA
  Id bigint

ParentObjectTableB
  Id bigint

ChildObjectTable
  Id bigint
  ParentId bigint
  ParentQualifier varchar(50)

解决方案

The following maps seem to work from an object perspective. I'm not overly keen on the idea of using crosstables, but I think this might be cleaner than trying to deal with inheritance. I'm going to take a look at that option as well and I'll post my findings here for the sake of completion. Comments welcome.

Mapping of ParentObjectA

<map name="Children" table="ParentAxChildObject">
    <key column="ParentId" />
    <index column="ChildObjectNumber" type="Int32" />
    <many-to-many class="ChildObject" />
</map>

Mapping of ParentObjectB

<map name="Children" table="ParentBxChildObject">
    <key column="ParentId" />
    <index column="ChildObjectNumber" type="Int32" />
    <many-to-many class="ChildObject" />
</map>

These generate the following cross tables:

ParentAxChildObject
    [ParentId] [bigint] NOT NULL,
    [elt] [bigint] NOT NULL,
    [ChildObjectNumber] [int] NOT NULL,

ParentBxChildObject
    [ParentId] [bigint] NOT NULL,
    [elt] [bigint] NOT NULL,
    [ChildObjectNumber] [int] NOT NULL,

这篇关于NHibernate的:我如何多发性父母的一种常见类型的儿童映射到一个单一的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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