简体   繁体   English

具有复合主键/外键的流畅Nhibernate每实体表映射

[英]Fluent Nhibernate Table-Per-Entity Mapping with Composite Primary/Foreign Keys

In .hbm.xml the mapping I am after would look as follows - any idea how I can reproduce this in Fluent NHibernate...? 在.hbm.xml中,我要执行的映射如下所示-知道如何在Fluent NHibernate中重现它吗?

    <class name="Dinosaur" table="Dinosaur" >
    <composite-id>
        <key-property name="Id" column="Id"/>
        <key-property name="Period" column="Period"/>
    </composite-id>
    <property name="DinosaurType" column="DinosaurType"  /> 
<joined-subclass name="Tyranosaur" table="Tyranosaur">
    <key>
        <column name="DinosaurId"/>
        <column name="DinosaurPeriod"/>
    </key>
    <property name="NumberOfTeeth">
        <column name="NumberOfTeeth">
        </column>
    </property>
</joined-subclass>

At the moment I have 此刻我有

public class DinosaurMap : ClassMap<Dinosaur>
{
    public DinosaurMap()
    {
    Table("Dinosaur");
    CompositeId()
        .KeyProperty(x => x.Id, "Id")
        .KeyProperty(x => x.Period, "Period")
    ;
    Map(x=>x.DinosaurType)
    ;
    }
}
public class TyranosaurMap : SubclassMap<Tyranosaur>
{
    public TyranosaurMap() 
    {
        Map(x=>x.NumberOfTeeth);
    }
}

but I can't figure out how, in the Tyranosaur SubclassMap, to specify the composite key. 但我不知道如何在Tyranosaur SubclassMap中指定组合键。 An issue on the NHibernate issue tracker suggest that this has been fixed in the 1.0 RTM build (I am using 1.0.0.593) NHibernate问题追踪器上的一个问题表明,此问题已在1.0 RTM版本中修复(我正在使用1.0.0.593)

找到了答案-您需要多次调用.KeyColumn方法以添加列-也许.AddKeyColumn会是一个更好的名称...?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM