Nhibernate Castle ActiveRecord类表继承

Nhibernate Castle ActiveRecord类表继承,nhibernate,inheritance,castle-activerecord,Nhibernate,Inheritance,Castle Activerecord,我正在尝试创建类表继承,如() 假设我有两门课: [ActiveRecord("entity"), JoinedBase] public class Entity : ActiveRecordBase { private int id; private string name; private string type; ...and properties } [ActiveRecord("entitycompany")] public class CompanyEntity

我正在尝试创建类表继承,如()

假设我有两门课:

[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; }
  }
}
看起来还好,所有的测试都很好。我在profiler中看到的一件事让我抓狂,那个就是若在其他类(我们称之为World)中使用了实体(它是一个属性),那个么获取世界将导致实体和公司实体的左外连接。 我希望它只是一个加入实体

有人能帮我解释一下为什么会这样吗?

ActiveRecord(实际上是NHibernate)必须在CompanyEntity上进行左连接,因为它必须知道实体的真正类型。如果不加入CompanyEntity,它就不可能知道它是否是CompanyEntity,所以它不知道实例化什么

换句话说,如果没有这个左连接,您的类层次结构将中断


它实际上不会导致任何显著的性能问题,但如果它困扰您那么多,请尝试切换到其他继承策略,如discriminator。

很好的一种,谢谢!!无法切换到鉴别器,因为我的子对象都依赖于父对象中的同一列-我认为这消除了鉴别器的可能性。