views:

169

answers:

1

In .hbm.xml the mapping I am after would look as follows - any idea how I can reproduce this in 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. 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)

+1  A: 

Found the answer - you need to make multiple calls to the .KeyColumn method to add the columns - perhaps .AddKeyColumn would have been a better name for it...?

Matt
yes, you have to call the KeyColumn method in the SubclassMap!
Falcon