views:

244

answers:

3

Hi all

My model looks like this:

public class SelectionItem : BaseEntity // BaseEntity ==> id, timestamp stuff
{//blabla}

public class Size : SelectionItem
{//blabla}

public class Adultsize : Size
{//blabla}

I would like to use class-hierarchy-per-table-method of fluent nhibernate

public class SelectionItemMap : BaseEntityMap<Entities.SelectionItem.SelectionItem>
{
    public SelectionItemMap()
    {
        Map(x => x.Name);
        Map(x => x.Picture);
        Map(x => x.Code);
        DiscriminateSubClassesOnColumn("SelectionItemType");
    }
}

and reset a DiscriminateSubClassesOnColumn on the following subclass:

public class SizeMap : SubclassMap<Size>
{
    DiscriminateSubClassesOnColumn("SizeType")
}

public Adultsize : SubclassMap<Adultsize>
{}

But this doesn't work.

I found a solution on the web: link text but this method is depreciated according to resharper.

How to solve it? thank you for further informations.

A: 

When you use class-hierarchy-per-table-method use use one column as discriminator and then define the value of that descriminator for each concrete class.

Try something like this:

    public class SelectionItem : ClassMap<SelectionItem>
    {
        public SelectionItem()
        {
            Id(x => x.Id);
            DiscriminateSubClassesOnColumn("SelectionItemType");
        }
    }

    public class Size : SubclassMap<Size>
    {
        public Size()
        {
             DiscriminatorValue("Size")
             DiscriminateSubClassesOnColumn("SizeType");
        }
    }

    public class Adultsize : SubclassMap<Adultsize>
    {
        public Adultsize()
        {
             DiscriminatorValue("Adult")
        }
  }
Torkel
Hi Torkel Thx a lot. it worked like a charm.Just one thing - I didn't set a discriminator value and fluent took the class name as discriminator value.
Xavier Hayoz
Hi! This doesn't work in FNH 1.1, nor in 1.0 RC.
DaeMoohn
+1  A: 

This doesn't work, DiscriminateSubClassesOnColumn() isn't available in a SubclassMap.

sam
A: 

Hi everbody.

You don't need to add DiscriminateSubClassesOnColumn() in the SubclassMap. It takes the classname as discriminator value.

Correct version of code

public class SelectionItem : ClassMap<SelectionItem>
{
    public SelectionItem()
    {
        Id(x => x.Id);
        DiscriminateSubClassesOnColumn("SelectionItemType");
    }
}

public class Size : SubclassMap<Size>
{
}

public class Adultsize : SubclassMap<Adultsize>
{
}
Xavier Hayoz

related questions