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 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

Ask A Question

Stats

  • Questions 184k
  • Answers 184k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What you are experiencing is not standard behavior. When removing… May 12, 2026 at 4:52 pm
  • Editorial Team
    Editorial Team added an answer Make sure you are sending your AWS keypair as the… May 12, 2026 at 4:52 pm
  • Editorial Team
    Editorial Team added an answer I think you want something like this: CSS: div#navBar {… May 12, 2026 at 4:52 pm

Related Questions

I've just received a new data source for my application which inserts data into
Using SQL Server 2005, I have a table where certain events are being logged,
In my last job, we worked on a very database-heavy application, and I developed
Single and multiple lists Consider the following lists: List<Int32> appleIdentities = new List<int>(new[] {

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.