Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate select column with SqlFunction, group by same criteria
    text
    copied!<p>I need to query for a count based on each day as well as group by the same criteria. The generated query should look similar to</p> <pre><code>select SendTo, dateadd(dd, 0, datediff(dd, 0, WorkToBeginDate)) from Locates group by SendTo, dateadd(dd, 0, datediff(dd, 0, WorkToBeginDate)) </code></pre> <p>I'm currently using the query below but it does not group by the <code>date</code>.</p> <pre><code>var dateGroupBy = Projections.SqlFunction("date", NHibernateUtil.Date, Projections.Group&lt;Domain.Locate&gt;(g =&gt; g.WorkToBeginDate)); var stats = _session.QueryOver&lt;Domain.Locate&gt;() .SelectList(x =&gt; x .SelectGroup(xx =&gt; xx.SendTo).WithAlias(() =&gt; statsDto.SentTo) .SelectCount(xx =&gt; xx.LocateId).WithAlias(() =&gt; statsDto.Count) .Select(dateGroupBy) .WithAlias(() =&gt; statsDto.DueDate)) .TransformUsing(Transformers.AliasToBean&lt;StatsDto&gt;()) .List&lt;StatsDto&gt;(); </code></pre> <p>Executing this query yields</p> <pre><code>SELECT this_.SendTo as y0_, count(this_.LocateId) as y1_, dateadd(dd, 0, datediff(dd, 0, this_.WorkToBeginDate)) as y2_ FROM Locates this_ GROUP BY this_.SendTo, this_.WorkToBeginDate </code></pre> <p>I'm assuming it's because I'm using <code>Select</code> and not <code>SelectGroup</code> in my projections. I have tried <code>.SelectGroup(xx =&gt; new SqlFunctionProjection("date", NHibernateUtil.Date, Projections.Group&lt;Domain.Locate&gt;(g =&gt; g.WorkToBeginDate)))</code>, however this gives me <code>Could not determine member from new SqlFunctionProjection("date", NHibernateUtil.Date, new [] {Group(g =&gt; Convert(g.WorkToBeginDate))})</code>.</p>
 

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