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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:33:21+00:00 2026-05-12T19:33:21+00:00

I am searching for the Linq-to-SQL equivalent to this query: SELECT [cnt]=COUNT(*), [colB]=SUM(colB), [colC]=SUM(colC),

  • 0

I am searching for the Linq-to-SQL equivalent to this query:

SELECT
  [cnt]=COUNT(*),
  [colB]=SUM(colB),
  [colC]=SUM(colC),
  [colD]=SUM(colD)
FROM myTable

This is an aggregate without a group by. I can’t seem to find any way to do this, short of issuing four separate queries (one Count and three Sum). Any ideas?

  • 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-12T19:33:22+00:00Added an answer on May 12, 2026 at 7:33 pm

    This is what I found seems like you still have to do a group by…can just use constant:

    var orderTotals =
        from ord in dc.Orders
        group ord by 1 into og
        select new
        {
            prop1 = og.Sum(item=> item.Col1),
            prop2 = og.Sum(item => item.Col2),
            prop3 = og.Count(item => item.Col3)
        };
    

    This produces the following SQL, which is not optimal, but works:

    SELECT SUM([Col1]) as [prop1], SUM([Col2]) as [prop2], COUNT(*) AS [prop3]
    FROM (
        SELECT 1 AS [value], [t0].[Col1], [t0].[Col2], [t0].[Col3]
        FROM [table] AS [t0]
        ) AS [t1]
    GROUP BY [t1].[value]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a LINQ query which is searching a SQL table of around 250,000
I'm new at LINQ, searching the net for LINQ samples that mimic SQL's LIKE
This LINQ and lambda expressions are killing me, so there is me again searching
I have been searching for way to perform a linq query to get an
While searching for linq conditional where clause, I found this article , the way
I was searching for a solution to permform a linq query and ignore case.
I am trying to convert the following SQL into NHibernate: SELECT * FROM dbo.Customer
been searching for a quick example of sorting a IQueryable (Using Linq To SQL)
I'm searching for a linq-to-objects way to get a TreeViewItem from a treeView. I
Searching here I found that this question was already asked , but I think

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.