Al.
Al.

Reputation: 167

Table-Per-SubClass not working

have a rather simple (or so I would think!) problem which is starting to annoy the hell out of me.

I have a simple set of classes.

The base Class "Product" is inherited by other classes, Product has a string Discriminator column "ProductType" which should allow NH to return the correct subclass.

Below is a simple version of what I am working on.

 public class ProductMap : ClassMap<Product>
{
    public ProductMap()
    {

        Table("Product");
        Id(x => x.Id)
            .GeneratedBy.Identity();

        DiscriminateSubClassesOnColumn("ProductType");


        Map(x => x.Name)
            .Length(200);
        Map(x => x.BriefDescription)
            .Length(400);

        Map(x => x.FullDescription);

        Map(x => x.Sku);
        Map(x => x.VendorSku);

        References(x => x.Vendor, "VendorId");


    }
}

public class MotorHomeMap : SubclassMap<MotorHome>
{
    public MotorHomeMap()
    {
        DiscriminatorValue("MotorHome");

        Table("MotorHome");


        //KeyColumn("ProductId");
        Map(x => x.Berths);


    }
}

However if I do a simple Session.QueryOver.List() the resulting query that gets executed is

SELECT this_.Id               as Id1_0_,
   this_.Name             as Name1_0_,
   this_.BriefDescription as BriefDes4_1_0_,
   this_.FullDescription  as FullDesc5_1_0_,
   this_.Sku              as Sku1_0_,
   this_.VendorSku        as VendorSku1_0_,
   this_.VendorId         as VendorId1_0_,
   this_.Berths           as Berths1_0_,
   this_.ProductType      as ProductT2_1_0_

FROM Product this_

Obviously "Berths" is NOT in the Product table, rather it is in the "MotorHome" table.

I'm sure I'm missing something rather simple but cannot for the life of me figure out what I'm doing wrong here.

Any help would be greatly appreciated.

Upvotes: 1

Views: 112

Answers (1)

adriaanp
adriaanp

Reputation: 2074

By specifying DiscriminateSubClassesOnColumn you are configuring the mapping to be table-per-class-hierarchy and not table-per-subclass

Fluent mapping documentation on subclasses

Upvotes: 1

Related Questions