开发者

Castle ActiveRecord Class Table Inheritance

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:开发者_JAVA百科

[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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜