以下是我遇到的一个实际问题的抽象。
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; }
}
映射:
<class name="Base" table="base_table" xmlns="urn:nhibernate-mapping-2.2">
<id name="Id" column="id">
<generator class="assigned" />
</id>
<property name="Foo" column="Foo" />
<joined-subclass name="Sub" table="sub_table">
<key column="id" />
<property name="Bar" column="Bar" />
<many-to-one name="Other" column="other_id" />
</joined-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>
以下无法对子查询内的joined-subclass进行连接:
Session.Query<Other>().Where(o => o.Subs.Any(s => s.Foo == "xyz"));
Sql
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)]
抛出 GenericADOException 因为子查询中的 subs1_1_(例如 sub_table)没有 Foo。我必须在 Other 的映射中做些什么来使 Subs 与子查询中的 Base 完全结合吗?