如何在使用 ActiveRecord 时将类转换为继承类

发布于 2024-09-08 09:18:23 字数 866 浏览 4 评论 0原文

我有一个类 Project 和一个类 Case,它们继承自 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; }
        }
}

案例:

 [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'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 :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦醒时光 2024-09-15 09:18:23

请参阅NHibernate - 更改子类型
它谈论了鉴别器,但原则上答案是相同的:要么通过重构来避免这种情况,要么用原始 SQL 来解决它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文