3

I am using the NHibernate convention-based-mapping and I'm trying to work out how to map a multi-level inheritence structure

If I have the following class structure

class ClassA

class ClassB : ClassA

class ClassC : ClassB

and I want all three classes to represent a single table - "ClassC" in the database

in my configuration I have defined ClassA as the RootEntity

(as described here: http://fabiomaulo.blogspot.co.nz/2011/04/nhibernate-32-mapping-by-code_13.html)

public static void WithConventions(this ConventionModelMapper mapper, Configuration configuration)
{
    var baseEntityType = typeof(ClassA);
    mapper.IsRootEntity((type, declared) => baseEntityType.Equals(type.BaseType));

    ...
}

the resulting schema then creates separate tables for ClassB and ClassC both contain fields defined in ClassA

jimma
  • 31
  • 3

1 Answers1

0

In the ModelInspector, you have to return true for method IModelInspector.IsTablePerClassHierarchy. This will make all classes to be stored in the same table.

Ricardo Peres
  • 13,724
  • 5
  • 57
  • 74