How can I write in fluent linq syntax the “case when” sql statement?
select QueueItem, COUNT(*) as [Count],
SUM(CASE WHEN Queued = 0 THEN 1 ELSE 0 END) AS [Sent],
SUM(CASE WHEN Queued = 1 THEN 1 ELSE 0 END) AS Queued,
SUM(CASE WHEN Success = 1 THEN 1 ELSE 0 END) AS Exported,
SUM(CASE WHEN Success = 0 THEN 1 ELSE 0 END) AS Failed
from ExportQueue x
group by QueueItem
Is there some program that can convert SQL to LINQ? LinqPad maybe?
Ok, something like this. I’ll need a bit of info to be sure though
Is Queued a bit? That makes a difference in linq where it doesn’t in SQL.
I also don’t know your context names but you should get the idea.
EDIT You could also combine these by doing the case on the fly in the query. I always tend to write it out as above first as I work through it though as more complex aggregates can be a bit hard to debug if there’s errors: