我有一个看起来像这样的类设置:
public abstract class Parent
{
public virtual bool IsDeleted { get; set; }
}
public class Child : Parent
{
}
public class Other
{
public virtual ICollection<Child> Children { get; set; }
}
Child 被映射为 Parent 的联合子类。 Childen 被映射为多对一包。该包应用了一个名为 SoftDeletableFilter 的过滤器。过滤器映射如下所示:
<filter-def name="SoftDeleteableFilter" condition="(IsDeleted = 0 or IsDeleted is null)" />
问题是当加载 Other.Children 时,过滤器将应用于子表而不是父表。有没有办法告诉 NHibernate 将过滤器应用于父类?
编辑: 这是父映射:
<class name="Parent">
<id ..
<property name="IsDeleted" type="System.Boolean">
<column name="IsDeleted" />
</property>
<joined-subclass name="Child">
<key>
<column name="ParentId" />
</key>
...
</joined-subclass>
</class>
最佳答案
终于找到答案了。也许不是最友好的方法,但您可以将过滤条件重写为子查询:
ParentId in (Select p.ParentId from Parent p where p.IsDeleted = false)
感谢CSharper at the usergroup征求意见
关于c# - NHibernate 多对一连接子类与过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3050050/