Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are many things in NHibernate.Linq for NHibernate 2.1.2.4000 that just won't work. You could use HQL or ICriteria instead, or upgrade to NHibernate 3.0, or if you're going to use all the data, force your Linq query to execute after the <code>Select</code> by adding a <code>ToList</code>.</p> <pre><code>tags .Select(t = new { t.Name, t.Posts.Count }) .ToList() .OrderBy(x =&gt; x.Count); </code></pre> <p>The anonymous object by itself is something that NHibernate.Linq can definitely handle.</p> <p>By the way, you don't have to specify the field name in an anonymous object if it's the same as the field/property you're dragging it from.</p> <p>EDIT: An ICriteria version of this query would look like this...</p> <pre><code>var tags = session.CreateCriteria(typeof(Tag), "tag") .SetProjection( Projections.GroupProperty("tag.Name"), Projections.Count("tag.Posts")) .AddOrder(Order.Asc(Projections.Count("tag.Posts"))) .List(); </code></pre> <p>EDIT: With a proper mapping I'm getting the same SQL, Arch. My earlier mapping was wrong. This one seems to work however.</p> <pre><code>var tags = session.CreateCriteria(typeof(Tag), "tag") .CreateCriteria("tag.Posts", "post") .SetProjection( Projections.GroupProperty("tag.Name"), Projections.Count("post.Id")) .AddOrder(Order.Asc(Projections.Count("post.Id"))) .List(); </code></pre> <p>The SQL I get is this...</p> <pre><code>SELECT this_.Name as y0_, count(post1_.Id) as y1_ FROM Tag this_ inner join Post_Tags posts3_ on this_.Id=posts3_.Tag inner join Post post1_ on posts3_.Post=post1_.Id GROUP BY this_.Name ORDER BY count(post1_.Id) asc </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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