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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:19:11+00:00 2026-05-24T06:19:11+00:00

How should I structure a Linq query to return a List or Ienumerable of

  • 0

How should I structure a Linq query to return a List or Ienumerable of the most popular Tags in my db (I am using EF4.1 by the way).

Currently I have:

  var tagsListing = db.Tags
                            .GroupBy(q => q.Name)
                                .OrderByDescending(gp => gp.Count())
                                .Take(5)
                                .Select();

I think I am part of the way there, but I am unsure of how to structure the Select statement…

  • 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-24T06:19:12+00:00Added an answer on May 24, 2026 at 6:19 am

    Assuming you want the name and the count, just:

    .Select(g => new { Name = g.Key, Count = g.Count() });
    

    EDIT: If you want the complete tags as well, you could use:

    .Select(g => new { Tags = g, Count = g.Count() })
    

    which would give you a sequence of groups of tags, all with the same name within a group. Or you might only want the first tag within each group, e.g.

    .Select(g => g.First())
    

    It’s not clear what a Tag consists of, or what exactly you want in the results.

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

Sidebar

Related Questions

I have problems with how I should structure my product listing pages, products pages,
I have a following tables/classes structure in Linq to entities. Books { bookId, Title
I have a linq query to a XML dataset, which when executed is generating
I have just started evaluating whether or not I should be using OData influenced
I have two tables that I am using Linq to SQL with. The tables
I need to query an array. I have tried to use LINQ but with
I am wondering how I should structure a FAQ to keep the semantic meaning
How to create new table which structure should be same as another table I
I wonder what is the best C# data structure I should use to sort
I am trying to figure out what type of structure or container I should

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.