【发布时间】:2010-06-24 13:42:45
【问题描述】:
我正在使用“类表继承 - 使用连接的子类”,如下所述: http://www.castleproject.org/activerecord/documentation/trunk/usersguide/typehierarchy.html
下面的代码部分是从那里复制过来的。
[ActiveRecord("entity"), JoinedBase]
public class Entity : ActiveRecordBase
{
...
private int id;
[PrimaryKey]
private int Id
{
get { return id; }
set { id = value; }
}
}
[ActiveRecord("entitycompany")]
public class CompanyEntity : Entity
{
private int comp_id;
[JoinedKey("comp_id")]
public int CompId
{
get { return comp_id; }
set { comp_id = value; }
}
....
}
现在,当我加载了 CompanyEntity 并访问 ComId 属性时,它始终为 0,但继承的 Id 属性包含正确的值。
编辑:
我可能应该补充一点,我们的实体是自动生成的,我不想触摸生成器。
编辑2:
好的,我意识到我必须触摸发电机才能使其工作。但是为什么 Active Record 不设置 Comp_id 呢?
问题:
如何告诉 ActiveRecord 也设置子类中 JoinedKey 的值,以便 CompId == Id?
【问题讨论】:
标签: inheritance castle-activerecord hierarchy