NHibernate 多对一连接子类与过滤器
我有一个看起来像这样的类设置:
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>
I have a class setup that looks something like this:
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 is mapped as a joined-subclass of Parent.
Childen is mapped as a Many-To-One bag. The bag has a filter applied to it named SoftDeletableFilter. The filter mapping looks like:
<filter-def name="SoftDeleteableFilter" condition="(IsDeleted = 0 or IsDeleted is null)" />
That problem is that when Other.Children is loaded the filter is being applied to the Child table and not the parent table. Is there any way to tell NHibernate to apply the filter to the parent class?
Edit:
Here's the parent mapping:
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
终于找到了这个问题的答案。也许不是性能最友好的方法,但您可以将过滤条件重写为子查询:
感谢 CSharper 在用户组获取建议
Finally found an answer to this. Perhaps not the most performance friendly approach, but you can rewrite your filter condition as a subquery:
Thanks to CSharper over at the usergroup for the suggestion
您需要将过滤器添加到父类中:
you need to add the filter to the parent class: