views:

67

answers:

1

Hi,

Im trying to map the following classes:

public abstract class ScheduleType
{
    public virtual int Id { get; set; }
    public virtual TypeDiscriminatorEnum Discriminator { get; set; }
}

public class DerivedScheduleType : ScehduleType
{
    public virtual bool MyProperty { get; set; }
}



public class ScheduleTypeMap : ClassMap<ScheduleType>
{
    public ScheduleTypeMap()
    {
        Id(p => p.Id);
        Map(p => p.Discriminator).CustomType<TypeDiscriminatorEnum>().Not.Nullable();
    }
}

public class DerivedScheduleTypeMap : SubclassMap<DerivedScheduleType>
{
    public DerivedScheduleTypeMap()
    {
        //DiscriminatorValue(TypeDiscriminatorEnum.DerivedSchedule);
        Map(p => p.MyProperty);
    }
}

The problem is that queries on ScheduleType joins with all derived tables to find the right one.

I need something that says to NHibernate to join only with the table that represents the right subclass.

Any sugestions?

Thanks in advance!

+1  A: 

Use DiscriminateSubClassesOnColumn<TypeDiscriminatorEnum>("discriminator") instead of Map(p => p.Discriminator).

I'm not quite sure what you're trying to achieve though, because you're talking about joining other tables; discriminators aren't used with table-per-subclass, only in table-per-class-hierarchy.

James Gregory