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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:00:33+00:00 2026-06-11T18:00:33+00:00

I am looking for a way in C# LINQ using lambda format to group

  • 0

I am looking for a way in C# LINQ using lambda format to group records per second. in my search i have yet to find a good way to do this.

the SQL query is as follows.

select count(cct_id) as 'cnt'
  ,Year(cct_date_created) 
  ,Month(cct_date_created) 
  ,datepart(dd,cct_date_created) 
  ,datepart(hh,cct_date_created) 
  ,datepart(mi,cct_date_created) 
  ,datepart(ss,cct_date_created) 
from ams_transactions with (nolock)
where cct_date_created between dateadd(dd,-1,getdate()) and getdate()
group by 
  Year(cct_date_created)
  ,Month(cct_date_created)
  ,datepart(dd,cct_date_created)
  ,datepart(hh,cct_date_created)
  ,datepart(mi,cct_date_created)
  ,datepart(ss,cct_date_created)

now the closest i was able to come was the following but it is not giving me the right results.

var groupedResult = MyTable.Where(t => t.cct_date_created > start 
                                    && t.t.cct_date_created < end)
                           .GroupBy(t => new { t.cct_date_created.Month,
                                               t.cct_date_created.Day,
                                               t.cct_date_created.Hour,
                                               t.cct_date_created.Minute, 
                                               t.cct_date_created.Second })
                           .Select(group => new { 
                                                 TPS = group.Key.Second
                                                });

this appears to be grouping by seconds but not considering it as per individual minute in the date range and instead that second of every minute in the date range. To get Transactions per second i need it to consider each minute of the month, hour, day, minute separately.

The goal will be to pull a Max and Average then from this grouped list. Any help would be greatly appreciated 🙂

  • 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-11T18:00:34+00:00Added an answer on June 11, 2026 at 6:00 pm

    Currently you’re selecting the second, rather than the count – why? (You’re also using an anonymous type for no obvious reason – whenever you have a single property, consider just selecting that property instead of wrapping it in an anonymous type.)

    So change your Select to:

     .Select(group => new { Key = group.Key,
                            Transactions = group.Count() });
    

    Or to have all of the key properties separately:

     .Select(group => new { group.Month,
                            group.Day,
                            group.Hour,
                            group.Minute,
                            group.Second,
                            Transactions = group.Count() });
    

    (As an aside, do you definitely not need the year part? It’s in your SQL…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking at better way of writing following code using linq/lambda expression.. I
I'm looking for a good guide into the right method of using Linq to
I'm looking for a good way to convert an XmlDocument to Dictionary<string, string> using
Looking for a way to group in sets of n elements with LINQ. I.e:
I am looking for a more sophisticated way of using Linq to SQL. I
I am looking for a way to call a stored procedure with Linq except
I am using codeigniter and looking a way to enable directly editting of doc
Is there some way of detecting whether an enumerable built using LINQ (to Objects
I'm looking at using LINQ to SQL for a new project I'm working on,
I'm using VB.NET on Framework 2.0. I'm looking to quickly group a Generic List<>

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.