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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:01:04+00:00 2026-06-03T16:01:04+00:00

Is it possible in LINQ to do this: Group by a field (LineTotal), returning

  • 0

Is it possible in LINQ to do this: Group by a field (LineTotal), returning only the top 9 groups and then in the 10th group return the sum of all other groups?

In SQL server this can be done like so:

with TopGroups as 
(
    select sum(sol.LineTotal) as ProductGroupSales, p.ProductGroupId,
    ROW_NUMBER() OVER(ORDER BY sum(sol.LineTotal) DESC) as Num
    from SalesOrderLines sol left join Products p on p.Id = sol.ProductId
    group by p.ProductGroupId
)
select ProductGroupSales from TopGroups where Num < 10
union all
select sum(ProductGroupSales) from TopGroups where Num >= 10

Can this be translated to LINQ? I’m not sure how ROW_NUMBER() OVER() and union all translate to LINQ.

  • 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-03T16:01:07+00:00Added an answer on June 3, 2026 at 4:01 pm
    1. You can translate the row number using “.Take(9)” and “.Skip(0).Take(1)“.
    2. UNION ALL maps to seqA.Concat(seqB)
    3. A CTE maps to just a variable holding a query. Like so:

    –

    var q1 = SalesOrderLines.Where(...);
    var q2 = q1.Concat(q1); //reused q1 multiple times for q2 like a CTE
    

    All of these basically come at no performance cost on the SQL side.

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

Sidebar

Related Questions

Possible Duplicate: LINQ to SQL: Return anonymous type? This is my code: class B
Possible Duplicate: LINQ to SQL: Return anonymous type? I have a standard LINQ to
Is it possible to use all features of Linq to SQL for a MySQL
Is it possible using Linq to create a group where items fall into more
I'm trying to subgroup a group using linq. This is proving to be more
I'm not sure if this is possible in LINQ, but I have the following
Possible Duplicate: linq to sql recursive query I got stuck with having to build
I have a unique requirement that I hope is possible with LINQ to SQL.
Is it possible to use LINQ in the express version of visual studio? I
I am wondering if it is possible to use Linq functionality to connect to

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.