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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:01:33+00:00 2026-06-14T16:01:33+00:00

I have a table in my SQL Anywhere 12.0.1 database: CREATE TABLE Entries (

  • 0

I have a table in my SQL Anywhere 12.0.1 database:

CREATE TABLE Entries (
    ListId        UNIQUEIDENTIFIER NOT NULL,
    . . .
);

I need to query the table to get the number of rows in the table that have the same ListID. In SQL:

SELECT ListID, COUNT(*)
FROM Entries
GROUP BY ListId;

I want to execute this query using Entity Framework 4.x, and I want to return the results as a Dictionary<Guid, long>. Something like this:

public Dictionary<Guid, long> GetRowCounts( MyEntities context ) {
    Dictionary<Guid, long> result = null;
    try {
        result = ( from entry in Entries
                   group entry by entry.ListId into listGroup
                   select listGroup ).ToDictionary( grp => grp.Key, ???? );

    } catch ( Exception ex ) {
        . . .
    }
    return result;
}

Remember, I want the count of rows that have each unique ListId returned. What do I put in place of the “????”?

  • 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-14T16:01:35+00:00Added an answer on June 14, 2026 at 4:01 pm

    Well, look at what you wrote:

    Remember, I want the count of rows

    (emphasis mine). So you need:

    ToDictionary(grp => grp.Key, grp => grp.Count())
    

    Personally I’d write the method like this though:

    public Dictionary<Guid, int> GetRowCounts(MyEntities context) {
        return context.Entries
                      .GroupBy(entry => entry.ListId)
                      .ToDictionary(g => g.Key, g => g.Count());
    }
    

    … or if you still want it to be a Dictionary<Guid, long>, use g => g.LongCount(), or just cast:

    .ToDictionary(g => g.Key, g => (long) g.Count())
    

    You almost certainly don’t want the try/catch block there, and returning directly is a lot simpler. Likewise, unless you’re writing a moderately complex query, there’s really no benefit in using a query expression. Learn to use the extension methods directly too, so that for each query you can write the simplest possible code.

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

Sidebar

Related Questions

I have a table in SQL server: Categories -------------- CategoryID (uniqueidentifier) ParentCategoryID (uniqueidentifier) allow
I am trying to execute an SQL query on an Adaptive Server Anywhere database.
I have a table in SQL Server 2008 Table Name : tbl_device Table Structure:
I have a table in sql 2008 named tblEmployeeAttendance like Here is some dummy
I have a table in SQL Server called [Donations] that contains donations given by
I have a table in SQL Server 2005 which has a date time field.
I have a table in sql where the date format is stored in Hijri.
I have a table in SQL Server 2005. alt text http://www.techpint.com/sites/default/files/images/table.JPG I want to
I have a table in SQL that links to itself through parentID. I want
I have a table in SQL Server, where i want inserts to be added

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.