NHibernate的<加入/>使用过滤器 [英] NHibernate <Join/> with filters

查看:122
本文介绍了NHibernate的<加入/>使用过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望会有一个简单的答案,这一次......

I was hoping there would be a simple answer to this one....

我有安排,以避免数据库软删除一个全球性的过滤器,这个工作正常,在我的系统的其余部分。但是,我们使用的是传统的数据库与现有的的用户群表格中,我们所需要的任何新特性,我们增加了用户表,并映射我们的User类检索数据从使用加入映射2表 - 这样一来,我们不改变现有的的用户群

I have a global filter designed to avoid soft deletes in the database, this works fine in the rest of my system. However we are using a legacy database with an existing "UserBase" table, any new properties we required we added to a "User" table and mapped our User class to retrieve data from 2 tables using the "join" mapping - this way we are not altering the existing "UserBase" table.

同样,这工作得很好,直到我们尝试应用软删除过滤器的类 - 作为生成的SQL应用过滤器的 BaseUser 表,其中没有匹配的列

Again this works fine, until we try to apply the soft delete filter to the class - as the generated SQL applies the filter to the "BaseUser" table where there is no matching column.

 <class name="User" table="UserBase">
    <id name="Id" column="userid" type="Int32" unsaved-value="-1">
        <generator class="native">
            <param name="sequence"></param>
        </generator>
    </id>
    <property name="Email" column="UserEmail" type="String" length="100" />
    .........
    .........
    <join table="User" optional="false">
     <key column="UserID"  />
     <property name="TimeZone" column="timezone" type="Int32" />
     .........
     .........
     <property name="IsDeleted" column="IsDeleted" type="Boolean" />
    </join>

    <filter name="AvoidLogicalDeleted" condition="IsDeleted = 0" />
 </class>

有没有什么办法,我可以得到过滤器适用于已连接表中,而不是在类表?

Is there any way that I can get the filter to apply to the "joined" table, rather than the class table?

我也试图在加入映射指定用一个子查询where子句忽略软删除,但它似乎被忽略!?

I have also tried to specify a "subselect" in the "join" mapping with a where clause ignoring soft deletes, but it appears to be ignored!?

在正确的方向有一点是很大的AP preciated ....

A point in the right direction would be greatly appreciated....

推荐答案

我不知道我有一个答案,而是一种变通。相反,映射用户类到的的用户群的表,然后加盟,给的用户的表,怎么样使用视图?也许你可以创建称为数据库的 UserView 的其拥有的的用户群用户的表连接,然后映射用户类的观点。 NHibernate的应该那么对待的请将isDeleted 的像任何其他列的筛选列应该工作。

I'm not sure I have an answer so much as a work around. Instead of mapping the User class to the UserBase table and then joined to the User table, what about using a view? Perhaps you can create a view in the database called UserView which has the UserBase and User tables joined and then map the User class to that view. NHibernate should then treat the IsDeleted column like any other column and the filter should work.

这是发生在我的另一个选择是从的的用户群的交换用户的映射类的用户的。在请将isDeleted 的列然后不再是连接表,但在连接到用户主表。然后,一个事实,即过滤器不工作的连接表都不会有问题。

Another option that occurred to me is to swap the mapping of the User class from UserBase to User. The IsDeleted column will then no longer be in the joined table but in the main table connected to User. Then, the fact that the filter isn't working on a joined table won't matter.

这篇关于NHibernate的&LT;加入/&GT;使用过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆