Castle ActiveRecord JoinedKey 未设置
我正在使用“类表继承 - 使用连接的子类”,如下所述: 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?
I am using "Class Table Inheritance - Using joined subclasses" as described here:
http://www.castleproject.org/activerecord/documentation/trunk/usersguide/typehierarchy.html
The following code is partly copied from there.
[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; }
}
....
}
Now when I have a CompanyEntity loaded and access the ComId property it is always 0, but the inherited Id Property contains the correct value.
Edit:
I Probably should add that our Entities are automatically generate and I do not want to touch the generator.
Edit2:
Ok, I realize that I have to touch the generator in order to make it work. But still why isn't Active Record setting the Comp_id?
Question:
How can I tell ActiveRecord to also set the value of the JoinedKey in the child class so that CompId == Id?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你需要使用:
...他们给出的例子是错误的。
I think you need to use:
... and the example they give is wrong.
这是一个很老的问题,但我遇到了同样的问题。 Castle.ActiveRecord 页面上的示例是错误的。
您可以像这样解决问题(带有注释修改的代码示例):
我刚刚用我的类型层次结构成功地测试了它。
This is quite an old question, but I ran into the same problem. The example on the Castle.ActiveRecord page is wrong.
You can solve the problem like this (your code example with commented modifications):
I've just successfully tested it with my type hierarchy.