NH Linq Group by Query

11 views
Skip to first unread message

reach4thelasers

unread,
Feb 9, 2009, 7:48:31 PM2/9/09
to nhusers
Hey guys,

I am having problems expressing a query in Linq to NH. Basically, I
have a discussion forum. On the home page I want to display the
threads that have been discussed the most in the last week; not the
threads with the most posts overall - the ones with the most posts in
the last week.

I can do it easy in SQL like so:
select threadid, COUNT(*) from dbo.forummessages where date >
'02/07/2009' group by threadid order by 2 desc

but I can't seem to be able to express it in LINQ - can anyone help me
out?

Here is my best effort:
var newthreads = from m in forumMessageDao.Messages
where m.Date > DateTime.Now.AddDays(-7)
group m by m.Thread
into t orderby t.Count() select new {Thread = t.Key,
PostsThisWeek = t.Count()};

but I get an exception could not resolve property: Key of:
Core.Domain.ForumMessage

Any ideas?

Kevin.

reach4thelasers

unread,
Feb 10, 2009, 7:46:03 AM2/10/09
to nhusers
Nobody??? :-(

On Feb 10, 12:48 am, reach4thelasers <kev.m.mul...@googlemail.com>
wrote:

Chad Lee

unread,
Feb 11, 2009, 4:07:35 PM2/11/09
to nhu...@googlegroups.com
Grouping queries are currently not well supported in nh.linq.  This is a bug you have run into.
Reply all
Reply to author
Forward
0 new messages