Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9248931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:04:11+00:00 2026-06-18T10:04:11+00:00

I have this code (not sure if it works as I can’t test it):

  • 0

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.

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:04:12+00:00Added an answer on June 18, 2026 at 10:04 am

    I would try:

    var test = ...Query<NutritionFact>()
                 .Where(x => x.NutritionalServing.Id == servingId)
                 .Select(x=> new { Nf= x, VfCount= x.UserVerifiedFacts.Count() })
                 .OrderByDescending(x => x.VfCount))
                 .Take(3)
                 .ToList();
    

    You don’t need to use Sum. The Sum is for aggregating (summarizing) the grouped columns, but you want just to Count() the number of rows in related table for each specific NuturitionFact.

    It corresponds to this SQL statement (which is, I suppose, what you need)

    SELECT TOP 3 n.*, 
           (SELECT COUNT(*) FROM UserVerifiedFact uv WHERE uv.NuturitionFacts_Id = n.Id) AS NumbOfVer  
           FROM NutritionFact n 
           WHERE n.NutritionalServing_Id = @servingId
           ORDER BY NumbOfVer DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure I can explain this properly.... I have the following sequence of code
I have this code in my cfm, which works <cfif not StructIsEmpty(form)> <cfset larray
Can someone please have a look at this code in which every function works
I'm not sure what is happening. I have this code: `case (XMLREADER::ELEMENT): $node_type =
I have this code for checking whether the Date is OK or not, but
I have this code $con = mysql_connect(localhost,root,); if (!$con) { die('Could not connect: '
In Python I have this code: now = datetime.now().isoformat() if . not in now:
In my appDelegate.m I have this code, but the UILabel is not displaying, but
Ok, I have this code. $con = mysql_connect(localhost,root,); if (!$con) { die('Could not connect:
I'm not good at t-sql, so I need help. I have this code I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.