混合继承映射策略NHibernate的 [英] Mixing inheritance mapping strategies in NHibernate

查看:133
本文介绍了混合继承映射策略NHibernate的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当大的继承层次结构中的一些子类中添加很少和其他人增加了不少。我不希望的全部的层次结构中使用映射的或者的表每类层次的的表每个子类,由于规模和层次结构的复杂性。理想的情况下,我想混合映射策略,使得分层结构的部分,其中的亚类添加很少被组合成一个共同的表,并且添加大量的子类一拉每个类层次表被分解成一个单独的表。使用这种方法,我希望有2或3个表用很少的浪费的空间,而不是任1表,有很多领域,并不适用于大多数的对象,或20+表,其中一些将只有一个情侣列。

I have a rather large inheritance hierarchy in which some of the subclasses add very little and others add quite a bit. I don't want to map the entire hierarchy using either "table per class hierarchy" or "table per subclass" due to the size and complexity of the hierarchy. Ideally I'd like to mix mapping strategies such that portions of the hierarchy where the subclasses add very little are combined into a common table a la "table per class hierarchy" and subclasses that add a lot are broken out into a separate table. Using this approach, I would expect to have 2 or 3 tables with very little wasted space instead of either 1 table with lots of fields that don't apply to most of the objects, or 20+ tables, several of which would have only a couple of columns.

在NHibernate的参考文档版本2.1.0,我发现的第8.1.4节每个子类混合每类层次结构表,表中。这种方法通过使用交换机策略中途沿层次:

In the NHibernate Reference Documentation version 2.1.0, I found section 8.1.4 "Mixing table per class hierarchy with table per subclass". This approach switches strategies partway down the hierarchy by using:

...
<subclass ...>
    <join ...>
        <property ...>
        ...
    </join>
</subclass>
...

这是伟大的理论。但在实践中,我发现,模式过于严格什么是允许的加盟的元素里面我能够完成我需要的东西。

This is great in theory. In practice, though, I found that the schema was too restrictive in what was allowed inside the "join" element for me to be able to accomplish what I needed.

下面是模式定义的相关部分:

Here is the related part of the schema definition:

<xs:element name="join">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="subselect" minOccurs="0" />
            <xs:element ref="comment" minOccurs="0" />
            <xs:element ref="key" />
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="property" />
                <xs:element ref="many-to-one" />
                <xs:element ref="component" />
                <xs:element ref="dynamic-component" />
                <xs:element ref="any" />
                <xs:element ref="map" />
                <xs:element ref="set" />
                <xs:element ref="list" />
                <xs:element ref="bag" />
                <xs:element ref="idbag" />
                <xs:element ref="array" />
                <xs:element ref="primitive-array" />
            </xs:choice>
            <xs:element ref="sql-insert" minOccurs="0" />
            <xs:element ref="sql-update" minOccurs="0" />
            <xs:element ref="sql-delete" minOccurs="0" />
        </xs:sequence>
        <xs:attribute name="table" use="required" type="xs:string" />
        <xs:attribute name="schema" type="xs:string" />
        <xs:attribute name="catalog" type="xs:string" />
        <xs:attribute name="subselect" type="xs:string" />
        <xs:attribute name="fetch" default="join">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="join" />
                    <xs:enumeration value="select" />
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="inverse" default="false" type="xs:boolean">
        </xs:attribute>
        <xs:attribute name="optional" default="false" type="xs:boolean">
        </xs:attribute>
    </xs:complexType>
</xs:element>

正如你所看到的,这允许使用属性子元素或组件子元素,而不是两个。它也不允许子类的子元素,以继续下面的点的层次结构,在该策略被改变。

As you can see, this allows the use of "property" child elements or "component" child elements, but not both. It also doesn't allow for "subclass" child elements to continue the hierarchy below the point at which the strategy was changed.

有没有办法做到这一点?

Is there a way to accomplish this?

推荐答案

您可能已经误读该模式。它清楚地表明,只要你想,你可以使用尽可能多的成分,性能和多对的。

You have probably misread that schema. It clearly shows that you can use as many components, properties and many-to-ones as you want.

不,这是不可能的,以增加更多的子类化战略里面。

And no, it's not possible to add more subclassing strategies inside it.

这篇关于混合继承映射策略NHibernate的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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