BrunoLM
BrunoLM

Reputation: 100322

How can I convert "SELECT col, COUNT(*)" to a Linq expression?

I have this query

SELECT Reaction, COUNT(*) as 'Votes' FROM Member_Reaction mr
    WHERE mr.[Entitiy ID] = '259F16A0-9635-4F58-B645-0AEBAAC09D46'
    GROUP BY Reaction

How can I convert this to Linq?

Upvotes: 1

Views: 142

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500065

Something like:

var query = from item in db.MemberReactions
            where item.ID == id
            group item by item.Reaction into g
            select new { Reaction = g.Key, Count = g.Count() };

(Where id is the ID you're looking for - as a GUID, or a string, or whatever the right type is.)

Upvotes: 7

Related Questions