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

  • SEARCH
  • Home
  • 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 3660608
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:13:24+00:00 2026-05-19T01:13:24+00:00

Hoping someone can help me with the LINQ syntax to calculate an average. For

  • 0

Hoping someone can help me with the LINQ syntax to calculate an average. For example, I have the following LINQ query:

var rates = from rating in ctx.Rates  
            where rating.Id == Id  
            select new 
            {   
                UserId = rating.UserId,  
                Rating = rating.Rating  
            };  

If 10 records are returned, I need to calculate average on the Rating field. It is defined as as a Double in my DB. I am using LINQ to EF. So I would be assigning the UserId, MiscId, and the Rating would be the average on the records returned. I am passing one object back to the client code.

  • 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-05-19T01:13:24+00:00Added an answer on May 19, 2026 at 1:13 am

    Are you looking for an average rating per user id? If so, then you need to use both GroupBy and Average.

    var rates = ctx.Rates
                   .Where( r => r.Id == Id )
                   .GroupBy( g => g.UserId, r => r.Rating )
                   .Select( g => new
                    {
                       UserId = g.Key,
                       Rating = g.Average()
                    }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am hoping someone can help me. I have the following function in FlashBuilder
im hoping someone can help me quickly with a question i have. As site
I'm hoping someone can help on this one, I have created a custom object
I am hoping someone can help me with a question i have relating to
I am hoping someone can help me out with a quick question I have
I'm hoping someone can help me. For my website I have a corresponding mobile
Hoping someone can help me design this correctly. In my TCP code, I have
I'm hoping someone can help me. I've got a specific Exception from COM that
Hoping someone can help with this. I have other VM's that dont have problems,
Im hoping someone can help me with a small problem! I have a php

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.