如何在使用 ActiveRecord 时将类转换为继承类
我有一个类 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅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.