开发者

How to convert class to inherited class while using ActiveRecord

开发者 https://www.devze.com 2023-01-05 14:19 出处:网络
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?

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 ho开发者_JAVA百科pe my subject and problem are clear :)


See 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消