I have this code (not sure if it works as I can’t test it):
var test = base.UnitOfWork.Session.Query<NutritionFact>()
.Where(x => x.NutritionalServing.Id == servingId)
.GroupBy(x => x.UserVerifiedFacts)
.OrderByDescending(x => x.Sum(e => e.UserVerifiedFacts.Count()))
.Take(3)
.Select(r => new
{
c = r.Key,
Sum = r.Sum(x => x.UserVerifiedFacts.Count())
})
.ToList();
What I am trying to do is find all NutritionFacts that have the correct servingId. I then want to count for each of those NutritionFacts found the count of how many users verified the information. I then want to get the top 3 results and use them.
What I am doing now results in a “not implemented” error that apparently is because nhibernate sum can only handle no parameters.

I would try:
You don’t need to use
Sum. TheSumis for aggregating (summarizing) the grouped columns, but you want just toCount()the number of rows in related table for each specificNuturitionFact.It corresponds to this SQL statement (which is, I suppose, what you need)