0
votes

I have something like the classes below, I'd like to map Foo to a single table with two columns, Id and State with values like 1, "BigState" and 2, "LittleState" but I'm really struggling to find examples of maps for this.

public class Foo 
{
    public int Id { get; set; }
    public State State { get; set; }
}

public abstract class State
{
}

public class BigState : State
{
}

public class LittleState : State
{
}
1
Are you using AutoMappingConfiguration?Alexey Rumyantsev
@AlexeyRumyantsev I believe so, yesTom

1 Answers

0
votes

https://nhibernate.info/doc/nhibernate-reference/inheritance.html

You are interested in table per class hierarchy strategy. Your second column would be discriminator column. When you are using FluentNhibernate you can derive from DefaultAutomappingConfiguration and override methods AbstractClassIsLayerSupertype, IsDiscriminated, GetDiscriminatorColumn. You also need to implement IClassConvention and ISubclassConvention to provide class name as discriminator value, something like that.

public class SubclassConvention : ISubclassConvention
{
    public void Apply(ISubclassInstance instance)
    {
        instance.DiscriminatorValue(instance.EntityType.Name);
    }
}