views:

43

answers:

2

What is the new SetAttribute() in FNH mapping? I need to set my discriminator value on subclass because String is not preferred - old post

with NH 2.1.2.4000, FNH 1.1.0.689

public class BaseBuildingMap : ClassMap<BaseBuilding>
{
    public BaseBuildingMap()
    {
        Id(x => x.Id);
        DiscriminateSubClassesOnColumn<int>("BuildingType", -1);
    }
}

public class PowerStationMap : SubclassMap<PowerStation>
{
    public PowerStationMap()
    {
        Map(x => x.ElectricityProduction);
    }
}

NHibernate.MappingException: Could not format discriminator value to SQL string of entity Model.Test.PowerStation ---> System.FormatException: Input string was not in a correct format.

I need to set SetAttribute("discriminator-value", "-1"); but there is no such method.

EDIT 1

Question: How to set discriminate column type for subclass with FNH?

+1  A: 

From Fluent NHibernate 1.0 Release Notes

Removed SetAttribute - SetAttribute was a stop-gap measure to allow people to use Fluent NHibernate when we didn't support the attributes they needed. We've now gone to a great length to support all of the main attributes in the fluent interface, so you shouldn't need this anymore. If there are any attributes you need that we've missed, let us know (or even better, send us a pull request/patch)

cbp
thanks, but this doesn't help... I've changed my question
Tomas Mirezko
A: 
public class PowerStationMap : SubclassMap<PowerStation>
{
    public PowerStationMap()
    {
        DiscriminatorValue((int)1);
        Map(x => x.ElectricityProduction);
    }
}

I've finally found my answer, it's

SubclassMap<T>::DiscriminatorValue(object discriminatorValue);
Tomas Mirezko