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 7933501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:21:10+00:00 2026-06-03T21:21:10+00:00

I have a LINQ in a method that is being passed an array of

  • 0

I have a LINQ in a method that is being passed an array of HalfHour objects, each of which contains a DateAndTime and a HalfHourNumber.

I need to query for each of these separately, and then average the result. Currently my query only works for the first element (I’m selecting element [1]):

internal static decimal? Average(this IQueryable<LOSSES> query, HalfHour[] array)
{
     var list = query.ToList();

     var numbers = (from q in list
                    where  q.DAY == array[1].DateAndTime.Date
                    select q).Select(x => Calculations.SingleElement(x, 
                    array[1].HalfHourNumber));

     return numbers.Average();

}

How would I prevent needing to do this within a loop (calling the query multiple times) yet keep the objects properties associated correctly?

  • 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-03T21:21:13+00:00Added an answer on June 3, 2026 at 9:21 pm

    To get a list of averages to go with your list of LOSSES:

    var averages = list.Select(
        q => array.Where(hh => q.DAY == hh.DateAndTime.Date)
                  .Select(hh => Calculations.SingleElement(q, hh.HalfHourNumber)
                  .Average()).ToList();
    

    Or, to associate each LOSSES with the average in a dictionary (if LOSSES supports being used as a key):

    var averages = list.ToDictionary(
        q => q,
        q => array.Where(hh => q.DAY == hh.DateAndTime.Date)
                  .Select(hh => Calculations.SingleElement(q, hh.HalfHourNumber)
                  .Average()
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a method that is being passed a vehicleID - I need to
I am overriding a method which has an XmlReader being passed in, I need
I have a LINQ statement that returns an anonymous type. I need to get
Hi I have a method to reset data objects by calling DataContext.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, Entity); .
I need to create a custom Contains LINQ expression that derives from System.Linq.Expressions.Expression that
I have a pretty complex linq statement I need to access for different methods.
I have some LINQ code that generates a list of strings, like this: var
I have a Linq query that looks something like this: var myPosse = from
I have this linq query that works well (although it may be written better,
I have a Linq query that looks something like this: var query = from

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.