I figured out a way to do this, though it may not be optimal in all
situations.  Just doing a .Distinct() on the LINQ query does, in fact,
produce a "distinct" in the resulting SQL query when used
without .Count().  If I cause the query to be enumerated by
using .Distinct().ToList() and then use the .Count() method on the
resulting in-memory collection, I get the result I want.

This is not exactly equivalent to what I was originally doing with the
Criteria query, since the counting is actually being done in the
application code, and the entire list of IDs must be sent from the DB
to the application.  In my case, though, given the small number of
distinct IDs, I think it will work, and won't be too much of a
performance bottleneck.

Is the limitation here a LINQ limitation, or simply that of the
current NHibernate.Linq implementation?  In other words, should I be
encouraging Microsoft or the NHibernate team to make "count(distinct
x)" in the resulting SQL query possible thru LINQ?

On Aug 11, 2:35 pm, Brian Sullivan <[email protected]> wrote:
> Thanks, Tuna!  Good to know.  I may just have to stick with my
> Criteria queries for now.
>
> On Aug 11, 11:07 am, Tuna Toksoz <[email protected]> wrote:
>
>
>
> > IIRC, no there is not a way to do this.
>
> > Tuna Toksöz
> > Eternal sunshine of the open source mind.
>
> >http://devlicio.us/blogs/tuna_toksozhttp://tunatoksoz.comhttp://twitt...
>
> > On Tue, Aug 11, 2009 at 7:04 PM, Brian Sullivan <[email protected]>wrote:
>
> > > No takers?  If I need to provide clarification on something, I'd be
> > > more than happy to.  I still can't figure this out!
>
> > > On Aug 8, 5:15 pm, Brian Sullivan <[email protected]> wrote:
> > > > I'm in the midst of trying to replace a the Criteria queries I'm using
> > > > for a multi-field search page with LINQ queries using the new LINQ
> > > > provider.  However, I'm running into a problem getting record counts
> > > > so that I can implement paging.  I'm trying to achieve a result
> > > > equivalent to that produced by aCountDistinctprojection from the
> > > > Criteria API using LINQ.  Is there a way to do this?  I can provide
> > > > the code I'm using if needed, but since there are so many fields, it's
> > > > pretty long, so I didn't want to crowd the post if it wasn't needed.
> > > > Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to