Castle ActiveRecord 类表继承

发布于 2024-09-06 02:59:01 字数 862 浏览 3 评论 0原文

我正在尝试创建类表继承,如 ( http:// www.castleproject.org/activerecord/documentation/trunk/usersguide/typehierarchy.html

所以假设我有 2 个类:

[ActiveRecord("entity"), JoinedBase]
public class Entity : ActiveRecordBase
{
  private int id;
  private string name;
  private string type;

  ...and properties
}

[ActiveRecord("entitycompany")]
public class CompanyEntity : Entity
{
  private byte company_type;
  private int comp_id;

  [JoinedKey("comp_id")]
  public int CompId
  {
    get { return comp_id; }
    set { comp_id = value; }
  }
}

看起来没问题,所有测试都很好。我在探查器中看到的一件事让我发疯,如果在其他类(我们称之为 World)中使用 Entity(它是一个属性),那么获取 World 会导致 Entity 和 CompanyEntity 上的左外连接。 我希望它只是实体的加入!

谁能帮助我并解释为什么会发生这种情况?

I'm trying to create Class Table Inheritance as in ( http://www.castleproject.org/activerecord/documentation/trunk/usersguide/typehierarchy.html )

So let's say I have 2 classes:

[ActiveRecord("entity"), JoinedBase]
public class Entity : ActiveRecordBase
{
  private int id;
  private string name;
  private string type;

  ...and properties
}

[ActiveRecord("entitycompany")]
public class CompanyEntity : Entity
{
  private byte company_type;
  private int comp_id;

  [JoinedKey("comp_id")]
  public int CompId
  {
    get { return comp_id; }
    set { comp_id = value; }
  }
}

It seems to be ok, all tests are fine. One thing I see in profiler and it drives me mad is that if Entity is used (it's a property) in some other class (let's call it World), then fetching World results in left outer join on both Entity and CompanyEntity.
I would expect it to be just a join on Entity!

Can anyone help me with that and explain why is it happening?

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

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

发布评论

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

评论(1

等你爱我 2024-09-13 02:59:02

ActiveRecord(实际上是 NHibernate)必须对 CompanyEntity 执行左连接,因为它必须知道实体的实际类型。如果没有离开 CompanyEntity,它就不可能知道它是否是 CompanyEntity,因此它不知道要实例化什么。

换句话说,如果没有这个左连接,你的类层次结构就会被破坏。

它实际上并不会导致任何重大的性能问题,但如果它让您感到困扰,请尝试切换到另一种继承策略,例如鉴别器。

ActiveRecord (actually NHibernate) has to do a left join on CompanyEntity because it has to know what type the Entity really is. Without left joining on CompanyEntity it can't possibly know if it's a CompanyEntity or not so it wouldn't know what to instantiate.

In other words, without this left join your class hierarchy would break.

It doesn't really cause any significant performance issues, but if it bothers you that much try switching to another inheritance strategy, like discriminator.

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