NHibernate Query with subselect Count error

946 views
Skip to first unread message

Paul

unread,
Mar 25, 2015, 3:19:12 PM3/25/15
to nhu...@googlegroups.com

I have the following query:

var list = repositoy.Query<MyClass>.Select(domain => new MyDto()
    
{
        
Id = domain.Id,
        
StringComma = string.Join(",", domain.MyList.Select(y => y.Name))
    
});

That works great:

list.ToList();

But if I try to get the Count I got an exception:

list.Count();

Exception

NHibernate.Hql.Ast.ANTLR.QuerySyntaxException

A recognition error occurred. [.Count[MyDto](.Select[MyClass,MyDto](NHibernate.Linq.NhQueryable`1[MyClass], Quote((domain, ) => (new MyDto()domain.Iddomain.Name.Join(p1, .Select[MyListClass,System.String](domain.MyList, (y, ) => (y.Name), ), ))), ), )]


Any idea how to fix that whithout using ToList ?

I posted that on StackOverflow as well

Gunnar Liljas

unread,
Mar 25, 2015, 5:36:56 PM3/25/15
to nhu...@googlegroups.com
You need to Count before the projection.

Feel free to report this as a bug. NH could throw away the projection when counting.

/G

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+u...@googlegroups.com.
To post to this group, send email to nhu...@googlegroups.com.
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Paul

unread,
Mar 26, 2015, 8:45:46 AM3/26/15
to nhu...@googlegroups.com
Thats so weird....

Thanks man

Paul

Gunnar Liljas

unread,
Mar 26, 2015, 12:36:22 PM3/26/15
to nhu...@googlegroups.com
I wouldn't call it weird. You have a "client side" projection (not a subselect), which can't reasonably be counted without ToList. 

Best regards

Reply all
Reply to author
Forward
0 new messages