user156888
user156888

Reputation:

NHIbernate Linq group by count

I have the version 3.0.0.1001 nhibernate.

My objects are basically modeiling a lineup at an event. So I have a StageSet object which represents one slot in the schedule for a stage.

Each StageSet object has a Stage and an Act property.

It also has many Users - people who have favorited the set.

I'm trying to ascertain the most popular sets that have been favorited using the following linq:

var topStars = from s in Db.StageSets
                           group s by s.Act.Id into g
                           select new { SetKey = g.Key, Count = g.Count() };

However this just fails with a Could not execute query[SQL: SQL not available] error

Should I be able to do this?

w://

Upvotes: 1

Views: 2437

Answers (3)

Firo
Firo

Reputation: 30813

in case someone comes here. The following should work with NH 3.1

var topStars = from s in Db.StageSets
               group s by s.Act.Id into g
               select new { SetKey = g.First().Act.Id, Count = g.Count() }

Upvotes: 3

Diego Mijelshon
Diego Mijelshon

Reputation: 52735

I just copied your query with a slightly different domain and it worked. But that will count StageSets by Act, NOT favorites.

Upvotes: 0

Amy B
Amy B

Reputation: 110121

You've specified the query correctly in linq. NHibernate is refusing to translate it.

Upvotes: 0

Related Questions