Mike Nichols - Son of Nun Technology

Active Record Quick Tip - Layer Superclass for Id property, etc.

This is noobie info for Castle's Active Record but I didn't see it explicitly in the docs after a cursory look so I thought I'd point it out here. It's so common it might help someone.

If you are implementing layer superclass for your domain and want to persist properties like 'Id' from that superclass, you might try this:

 

    [ActiveRecord]

    public abstract class Identifiable<T> : ActiveRecordBase<T>

    {

        private int id;

        [PrimaryKey]

        public virtual int Id

        {

            get { return id; }

            set { id = value; }

        }

    }

If you look in your Db, you'll see a table now created for your superclass! To avoid this, simply leave off the 'ActiveRecord' attribute on the superclass.