Creating the class Expense

Add a new class to your project with the name Expense. The code for this is:

using System;

using NDO;

namespace BusinessClasses

{

    [NDOPersistent]

    public abstract class Expense

    {

        DateTime date;

        public DateTime Date

        {

            get { return date; }

            set { date = value; }

        }

        public abstract string Text

        {

            get;

        }

        public abstract decimal Amount

        {

            get;

        }

        public Expense()

        {

        }

    }

}

Since the class Expense is abstract, it differs from the classes used so far. Classes derived from an abstract class have to implement the abstract properties. The subclasses inherit the date field (and the corresponding accessor) from the Expense class. The tables the subclasses are mapped to will provide a column to hold that date value.

If you take a look at the schema file TestApp.ndo.xsd, you will notice that there is no table for the class Expense. This makes sense because an abstract class will never have objects so no table in the database is needed.

If you start a build now and review NDOMapping.xml afterwards, you will note that there is a mapping entry for the Expense class; but the string unused is entered for most of the attributes. The reason why there is a mapping entry at all is that subclasses can inherit relations from abstract classes. All subclasses use the same intermediate table for a given relation. The name of the intermediate table is defined in the mapping entry of the base class.