Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate subquery when relation key is NULL, Count subquery
    primarykey
    data
    text
    <p>I wont to get count of subselect. I have:</p> <pre><code>Class A { int Id {get;set;} ICollection&lt;B&gt; NameBs {get;set;} } Class B { int Id {get;set;} C NameC {get;set;} } Class C { int Id {get;set;} } </code></pre> <p>My mapping look like:</p> <pre><code>&lt;class name="A" table="A"&gt; &lt;id name="Id" ...&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;set name="NameBs" table="B" inverse="true" cascade="all-delete-orphan" batch-size="20"&gt; &lt;key column="id_A" not-null="true" /&gt; &lt;one-to-many class="B" /&gt; &lt;/set&gt; &lt;/class&gt; &lt;class name="B" table="B"&gt; &lt;id name="Id" ...&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;many-to-one name="NameC" column ="id_C"/&gt; &lt;/class&gt; &lt;class name="C" table="C"&gt; &lt;id name="Id" ...&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;/class&gt; </code></pre> <p>Select in C# code is:</p> <pre><code>var results = (from a in aRep.QueryAll() select new myObject{ Id = b.Id, Count = a.NameBs.Count(b=&gt;b.C == null) }).ToList(); </code></pre> <p>SQL Select is:</p> <pre><code>SELECT Id, (SELECT cast(count(* ) as INT) FROM B b_, C c_ WHERE b_.id_c = c_.id AND b_.id_a = a_.id AND (b_.id_c is null)) FROM A a_ </code></pre> <p>But I need this select:</p> <pre><code>SELECT Id, (SELECT cast(count(* ) as INT) FROM B b_ WHERE b_.id_a = a_.id AND (b_.id_c is null)) FROM A a_ </code></pre> <p>Can anyone Help me?</p> <p>I have try mapping like: <strong>fetch="join"</strong> in many-to-one property, but is not work.</p> <pre><code>&lt;class name="B" table="B"&gt; &lt;id name="Id" ...&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;many-to-one name="NameC" column ="id_C" fetch="join"/&gt; &lt;/class&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload