Christian M
Christian M

Reputation: 488

Rewrite sql to linq, probably piece of cake, but can't get my head around it

I need to rewrite this sql statement in Linq.

select hand,count(hand) as Hands, deviceid from individualhands
where deviceid = '977aed93-d1f1-4f7a-a6fa-6bc3ea7d863b'
group by hand, deviceid

Can anybody help? :)

Upvotes: 1

Views: 45

Answers (1)

Serge Belov
Serge Belov

Reputation: 5803

Try this:

var query = individualHands
    .Where(r => r.deviceid == '977aed93-d1f1-4f7a-a6fa-6bc3ea7d863b')
    .GroupBy(r => new { r.hand, r.deviceid })
    .Select(g => new { hand = g.Key.hand, deviceid = g.Key.deviceid, Count = g.Count() });

Upvotes: 1

Related Questions