with filters I was hoping there would be a simple answer to this question .... I have a global filter that avoids soft del...">

NHibernate <Join / "> with filters

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

I have a global filter that avoids soft deletions in the database, this works fine in the rest of my system. However, we use an outdated database with an existing UserBase table, any new properties we need that we added to the User table, and we mapped our user class to extract data from 2 tables using the join join - this way we do not modify the existing table UserBase

Again, this works fine until we try to apply the soft delete filter to the class, because the generated SQL applies the filter to the BaseUser table, where there is no corresponding 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 a way I can get a filter to apply to a "joined" table, rather than a class table?

I also tried to specify a β€œsubtitle” in the β€œjoin” collation with the where clause, ignoring soft deletions, but it seems to be ignored !?

It would be helpful to evaluate the point in the right direction ....

+4
source share
1 answer

I am not sure that I have an answer, how work. Instead of matching the User class in the UserBase table and then joining the User table, what about using the view? Perhaps you can create a view in the UserView database that combines the UserBase and User tables, and then map the User class to this view. NHibernate then processes the IsDeleted column just like any other column, and the filter should work.

Another opportunity that arose for me was the exchange of data from the User class from UserBase to the user. The IsDeleted column will no longer be in the joined table, but in the main table associated with the User . Then the question that the filter does not work with the joined table does not matter.

+2
source

Source: https://habr.com/ru/post/1342969/


All Articles