The reference I've used while learning to use Castl'e ActiveRecord implementation is the Blog/Post demos that can be found on Castle's site.
Let's look at the Type Hierarchy example, that can be found here.
It shows an implementation of a class diagram that look a little bit like this:
Let's look at the code :
But look what happens. since the Id property on entity is public and inherited to the subclasses, you get something like this:
So there is a duplicate field here !!!. and it's not only a getter-setter thingie. It also have different private members.
My solution for this is to virtualize the base Id, and protectedize (hehe) the _id member, like this:
[ActiveRecord("entity"), JoinedBase]
public class Entity : ActiveRecordBase
{
protected int _id;
[PrimaryKey]
public virtual int Id
{
get { return id; }
set { id = value; }
}
}
[ActiveRecord("entitycompany")]
public class CompanyEntity : Entity
{
[JoinedKey("comp_id")]
public override int Id
{
get { return _id; }
set { _id = value; }
}
}
[ActiveRecord("entityperson")]
public class PersonEntity : Entity
{
[JoinedKey("person_id")]
public override int Id
{
get { return _id; }
set { _id = value; }
}
}
And before you hit me with a big stick - I do know of ActiveRecordBase<T> . :) the above code is for demonstration purposes only, not to be Copy&Pasted to your Brand-New-Best-Erp-Ever-Made-And-Will-Make-You-Rich