English 中文(简体)
在使用带有Nhebertate的工会子类时,是否必须指定一个抽象和无表基础类的表格?
原标题:Do you have to specify the table for an abstract and table-less baseclass when using union-subclass with NHibernate?

我们拥有一个基础元素, 我们所有其它域系都继承它。 在这个基础元素上是一些基本属性。 这可以像 < code> DateLast Change 一样 。

我们用 < code> hbm 映射文件使用Nhibertate。 我试图避免在每个映射文件中绘制 < code> DateLast Change 。

我发现, rel=“nofollow” > that post by Ayende,这让我相信我可以使用 union-sublike 来达到这个目的(见他最后的方法)。然而,他为他的抽象阶级添加了一张表格名称,不在表格里。

<class name="Party"
    abstract="true"
    table="Parties">
...

表格必须存在吗? 还是Nhebertate会忽略这个属性? 然后我可以省略它吗?

最佳回答

根据文件(感谢kalki):

<class name="Payment">
    <id name="id" type="long" column="PAYMENT_ID">
        <generator class="sequence"/>
    </id>
    <property name="amount" column="AMOUNT"/>
    ...
    <union-subclass name="CreditCardPayment" table="CREDIT_PAYMENT">
        <property name="creditCardType" column="CCTYPE"/>
        ...
    </union-subclass>
    <union-subclass name="CashPayment" table="CASH_PAYMENT">
        ...
    </union-subclass>
    <union-subclass name="ChequePayment" table="CHEQUE_PAYMENT">
        ...
    </union-subclass>
</class>

并且:

If your superclass is abstract, map it with abstract="true". If it is not abstract, an additional table (it defaults to PAYMENT in the example above), is needed to hold instances of the superclass.

问题回答

我有以下流利分子的抽象课目:

    public abstract class EntityMapping<TEntity> : ClassMap<TEntity> where TEntity : EntityBase
        {
            protected EntityMapping()
            {
                Id(x => x.Id, "Id")
                    .UnsavedValue("00000000-0000-0000-0000-000000000000")
                    .GeneratedBy.GuidComb()
                    .Index("IX_Lookup");
                OptimisticLock.Version();
                Version(x => x.Version);
Map(x=>x.DateLastChange); // your column
            }
        }

所有其他绘图都使用抽象类 :

public SomeEntityMap:EntityMapping<SomeEntity>{
   public SomeEntityMap(){
      Map(x=>x.SomeProperty);
   }
}




相关问题
Subclass check, is operator or enum check

A couple of friends was discussing the use of inheritance and how to check if a subclass is of a specific type and we decided to post it here on Stack. The debate was about if you should implement a ...

C++ Class Inheritance problem

Hi I have two classes, one called Instruction, one called LDI which inherits from instruction class. class Instruction{ protected: string name; int value; public: Instruction(string ...

Overloading a method in a subclass in C++

Suppose I have some code like this: class Base { public: virtual int Foo(int) = 0; }; class Derived : public Base { public: int Foo(int); virtual double Foo(double) = 0; }; ...

Embedding instead of inheritance in Go

What is your opinion of this design decision? What advantages does it have and what disadvantages? Links: Embedding description

Extending Flex FileReference class to contain another property

I want to extend the FileReference class of Flex to contain a custom property. I want to do this because AS3 doesn t let me pass arguments to functions through event listeners, which makes me feel sad,...

Interface Inheritance in C++

I have the following class structure: class InterfaceA { virtual void methodA =0; } class ClassA : public InterfaceA { void methodA(); } class InterfaceB : public InterfaceA { virtual ...

热门标签