0

I have a bunch of entities I'd like to list in a wiki-like manner, where they would be organized by the first letter of their title, followed by a count of how many entities exist per letter. So, something like:

A (5)
B (7)
C (4)
etc.

I'm not sure how to go about it, though. A rough pseudocode version:

from g in Games select g.title, /* count */ where /* g.title.firstLetter */ ASC 

The commented out parts are where I'm stuck. Any ideas?

3 Answers 3

5
from game in games group game by game.Title.Substring(0,1) into g select new { Key = g.Key, Count = g.Count() }; 

Free handed that, so there may be compiler errors, but I believe that should be the linq query to get you what you want.

Sign up to request clarification or add additional context in comments.

Comments

1
context.Games .GroupBy(g => g.title.FirstOrDefault()) .Select(g => new {g.Key, Count = g.Count()}) 

Comments

1
var query = from g in Games group g by g.title[0] into cg select new { FirstLetter = cg.Key, Count = cg.Count() }; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.