views:

19

answers:

1

I've got a class Project and a class Case, which inherits from Project. When having a list of Projects we might decide later on to make a Case of the selected Project. How can I achieve this?

Project:

[ActiveRecord (Table = "projects", Lazy = true), JoinedBase]
public class Project : ActiveRecordValidationBase<Project>
{
        private int _id;
        [PrimaryKey(PrimaryKeyType.Identity, "id")]
        public virtual int Id
        {
            get { return _id; }
            set { _id = value; }
        }
}

Case:

 [ActiveRecord(Table = "cases", Lazy = true)]
    public class Case : Project
    {
        private int _caseId;
        [JoinedKey("case_id")]
        public virtual int CaseId
        {
            get { return _caseId; }
            set { _caseId = value; }
        }
    }

I hope my subject and problem are clear :)

+1  A: 

See http://stackoverflow.com/questions/478296/nhibernate-changing-sub-types, it talks about discriminators, but in principle the answer is the same: either avoid this situation by refactoring, or hack around it with raw SQL.

Mauricio Scheffer