Layered Inheritance Using NHibernate Loquacious Mapping By Code

I am using NHibernate based mapping and I am trying to figure out how to map a multilevel inheritance framework

If I have the following class structure

class ClassA

class ClassB : ClassA

class ClassC : ClassB


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

in my config i have defined ClassA as RootEntity

(as described here: )

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 that contain the fields defined in ClassA


source to share

1 answer

In ModelInspector, you must return true for the IModelInspector.IsTablePerClassHierarchy method. This will result in all classes being stored in one table.



All Articles