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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:10:10+00:00 2026-05-11T14:10:10+00:00

How would the following sql query look when translated to linq? SELECT myId, Count(myId)

  • 0

How would the following sql query look when translated to linq?

SELECT     myId, Count(myId)  FROM MyTable  GROUP BY myId 

I’ve tried the following:

var q = from a in db.MyTable group a by a.Id into g let count = g.Count() select new {   Count = Id,   Key= g.Key }; 

but it raises an exception on enumeration indicating that there is no db function with a mapping named ‘Key’. I’m using LLBLGen on this particular app and I suspect that’s where the problem is rooted. I want to verify that my linq syntax is correct before I start digging though. Anyone see anything wrong?

  • 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. 2026-05-11T14:10:11+00:00Added an answer on May 11, 2026 at 2:10 pm

    Try this:

    var q = from a in db.MyTable         group a by a.Id into g         select new { Id=g.Key, Count=g.Count() }; 

    That’s nearly the same as yours, but your Count is obtained in a different way which looks wrong to me.

    If LLBLGen doesn’t understand IGrouping.Key though, it could be tricky…

    To check whether your LINQ syntax is correct or not, I’d recommend building a very simple in-memory list to use as your table. Here’s an example:

    using System; using System.Collections.Generic; using System.Linq;  class Test {     static void Main()     {         var data = new[] {             new { Id='X', Name='Jon' },             new { Id='Y', Name='Marc' },             new { Id='X', Name='Holly' },         };          var query = from a in data                     group a by a.Id into g                     select new { Id=g.Key, Count=g.Count() };          foreach (var entry in query)         {             Console.WriteLine(entry);         }     } } 

    This looks like it’s giving the right results to me.

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

Sidebar

Related Questions

How would the following sql statement translate to a linq query? select ID, Price,
Just wondering how the following sql query would look in linq for Entity Framework...
Imagine I have the following SQL query: SELECT id,name FROM user WHERE id IN
I would like to know how to write the following SQL query in Linq.
I have the following SQL query that performs horribly due to the select count(1)
I have the following SQL Query: SELECT porel.refcode, podetail.ponum, SUM(podetail.orderqty * podetail.unitcost) AS Total
How do you convert a SQL query with nested SELECT statements to a LINQ
I have the following SQL query. It returns NULL for the 'invoice_date'. SELECT *
I have the following result in AMFPHP from a sql query: (Array)#0 [0] (Object)#1
Would the following SQL remove also the index - or does it have 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.