Non-polymorphic Inheritance

Subclasses inherit the persistent fields from their base classes. This means that the tables associated with subclasses provide columns to store the fields of the base classes along with the fields of the derived class. Both the manipulation of persistent fields of the base class and of the subclass cause the object status to change to Persistent.Dirty so the object will be stored with the next call to PersistenceManager.Save.

Let's assume you have these classes:

[NDOPersistent]
public class Person
{
    string firstName;
    string lastName;
}
[NDOPersistent]
public class Employee
{
    string personalId;
}

The table in the database would have three columns: FirstName, LastName and PersonalId. This method avoids collecting the object data from different tables.

Important: The inheritance chain of persistent classes must not be broken. Suppose, you have an inheritance chain A, B, C. A and C are persistent classes, B is not marked as persistent. NDO would ignore the fields of the base class A. Here is a more concrete example for this:

[NDOPersistent]
public class BaseClass
{
    int baseField;
}
 
public class IntermediateClass : BaseClass
{
    DateTime intermediateField;
}
 
[NDOPersistent]
public class ChildClass : IntermediateClass
{
    string childField;
}

In this example the intermediate class IntermediateClass is not persistent. NDO cannot detect that ChildClass should inherit the field baseField. If you wish that NDO recognizes the fields of the BaseClass, the IntermediateClass also has to be marked persistent. You do not have to use it as a persistent class if you don’t wish to. Just mark the field intermediateField as NDOTransient to avoid that ChildClass inherits it as a persistent field.

[NDOPersistent]
public class BaseClass
{
    int baseField;
}
 
[NDOPersistent]
public class IntermediateClass : BaseClass
{
 
    [NDOTransient]
    DateTime intermediateField;
}
 
[NDOPersistent]
public class ChildClass : IntermediateClass
{
    string childField;
}