Maybe the question covers with an existing one, but I still can not find a solution.
I have 2 tables A and B. B has rating - it is very basic rating, so it keeps just reference to user and reference to item in table A. I want to select top rated items from table A.
So I tried this:
var innerQuery = from csr in session.Query<Rating>()
group csr by csr.ItemId into scrg
orderby scrg.Count() descending
select scrg.Key;
var result = from cs in session.Query<Item>() where innerQuery.Contains(cs.Id) select cs;
return result.Take(maxToReturn).ToList<Item>();
It is important for me to return List<Item>
But I have an exception:
Action: Index Exception: System.NotImplementedException: Cannot use group by with the ContainsResultOperator result operator.
at NHibernate.Linq.GroupBy.AggregatingGroupByRewriter.FlattenSubQuery(QueryModel queryModel, QueryModel subQueryModel)
at NHibernate.Linq.GroupBy.AggregatingGroupByRewriter.ReWrite(QueryModel queryModel)
at NHibernate.Linq.Visitors.QueryModelVisitor.GenerateHqlQuery(QueryModel queryModel, VisitorParameters parameters, Boolean root)
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitSubQueryExpression(SubQueryExpression expression)
at ............
Any ideas how to do it?
UPDATE:
My Item class is not related with the rating at all, I just count it during displaying the item, because it can be rated by anyone (so should be updated quite often), but I can add relationship if it will help?
Thanks guys,