C# NHibernate(3.1)子类上未加入基类表的子查询
下面是我遇到的一个实际问题的抽象C# NHibernate(3.1)子类上未加入基类表的子查询,c#,oracle,nhibernate,subquery,joined-subclass,C#,Oracle,Nhibernate,Subquery,Joined Subclass,下面是我遇到的一个实际问题的抽象 public class Base { public virtual string Id { get; set; } public virtual string Foo { get; set; } } public class Sub : Base { public virtual string Bar { get; set; } public virtual Other Other { get; set; } } publi
public class Base
{
public virtual string Id { get; set; }
public virtual string Foo { get; set; }
}
public class Sub : Base
{
public virtual string Bar { get; set; }
public virtual Other Other { get; set; }
}
public class Other
{
public virtual string Id { get; set; }
public virtual ICollection<Sub> Subs { get; set; }
}
由于子查询中的subs1_1_(例如sub_表)没有Foo,因此引发GenericADOException。
在其他人的映射中,我是否必须做些什么才能使子查询中的sub与Base完全联接?可能是与联接子类映射相关的linq提供程序问题。对于每个层次结构的表,该查询工作得很好。试试这个:
<class name="Base" table="base_table" xmlns="urn:nhibernate-mapping-2.2">
<id name="Id" column="id">
<generator class="assigned" />
</id>
<discriminator column="Type" type="String" />
<property name="Foo" column="Foo" />
<subclass name="Sub" discriminator-value="Sub">
<property name="Bar" column="Bar" />
<many-to-one name="Other" column="other_id" />
</subclass>
</class>
<class name="Other" table="other_table" xmlns="urn:nhibernate-mapping-2.2">
<id name="Id" column="id">
<generator class="assigned" />
</id>
<set name="Subs" inverse="true" lazy="true">
<key column="other_id" />
<one-to-many class="Sub" />
</set>
</class>
不幸的是,在所有情况下,每个层次结构的表都不能替换连接的子类
NH jira中注册的一些问题看起来类似(,),但不确定它们是否真的相关
编辑:
HQL也存在同样的问题:
来自其他存在的o(来自o.Subs s,其中s.Foo='xyz')
因此这不是与linq提供程序相关的问题。请不要用于格式化代码您有确切的SQL吗?加载基本属性时可能会比较懒。好的。。我已经添加了我得到的确切sql。您是否映射了您映射的实体的基本属性?是。。正如您所看到的,Foo是在Base中映射的。
Session.Query<Other>().Where(o => o.Subs.Any(s => s.Foo == "xyz"));
select
other0_.id as id60_
from
other_table other0_
where
exists (
select
subs1_.id
from
sub_table subs1_
where
other0_.id=subs1_.other_id
and subs1_1_.Foo=:p0
);
:p0 = 'xyz' [Type: String (0)]
<class name="Base" table="base_table" xmlns="urn:nhibernate-mapping-2.2">
<id name="Id" column="id">
<generator class="assigned" />
</id>
<discriminator column="Type" type="String" />
<property name="Foo" column="Foo" />
<subclass name="Sub" discriminator-value="Sub">
<property name="Bar" column="Bar" />
<many-to-one name="Other" column="other_id" />
</subclass>
</class>
<class name="Other" table="other_table" xmlns="urn:nhibernate-mapping-2.2">
<id name="Id" column="id">
<generator class="assigned" />
</id>
<set name="Subs" inverse="true" lazy="true">
<key column="other_id" />
<one-to-many class="Sub" />
</set>
</class>