Creating the Country Class

Add a new class with the name Country to the traveling expenses accounting project. Insert this code:

using System;

using System.Collections;

using NDO;

namespace BusinessClasses

{

    [NDOPersistent]

    public class Country

    {

        string name;

        public string Name

        {

            get { return name; }

            set { name = value; }

        }

   

        [NDORelation(typeof(Travel))]

        IList travels = new ArrayList();

        public void AddTravel(Travel t)

        {

            travels.Add(t);

        }

        public void RemoveTravel(Travel t)

        {

            if (travels.Contains(t))

                travels.Remove(t);

        }

        public IList Travels

        {

            get { return ArrayList.ReadOnly(travels); }

            set { travels = value; }

        }

        public Country()

        {

        }

    }

}

// Note: you can use the generic list

// classes as well if you wish.

Once again you find the common structure of persistent classes here. Please note that the relation to the class Travel is not a composite this time. Hence the Add Accessor function produces different code. Instead of NewTravel() there is a function AddTravel(). NDO assumes that the travel object already exists as an independent persistent object. Before calling AddTravel() the travel object has to be made persistent with the PersistenceManager function MakePersistent().