How to write this condition to the HBM NHibernate mapping?

So, I am in the know about the crash of NHibernate, and it seems to be trapped with the example below.

Suppose I have the following .NET class:

class A {
    int id;
    int type_var;
    List<B> someCollection;
}

class B {
    int id;
    string someText;
}

I will probably name it as:

<class name="A" table="A">
    <id name="id" type="Int32">
         <generator type="identity" />
    </id>
    <property name="type_var" />
    <set name="someCollection" table="B">
         <key name="fk_aid" />
         <composite-element class="B">
              <property name="someText" />
         </composite-element>
    </set>
</class>

My problem is how would you change this mapping if we were only interested in those elements of B that belong to A (via fk_aid) and have a value of type_var equal to A (let's say that both A and B have type_var column, but they are explicitly not connected).

I think I will have to work with something like a where clause here?

<set name="someCollection" table="B" where="type_var = type_var">

How exactly can this be done?

+3
source share
1 answer

, ( , RDMS ); - :

<set name="someCollection" table="B" where="type_var = (SELECT A.type_var FROM A WHERE A.fk_aid = id)"> 

, ; ; .

0

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


All Articles