How would I create the equivalent Linq To Objects query?
SELECT MIN(CASE WHEN p.type = 'In' THEN p.PunchTime ELSE NULL END ) AS EarliestIn, MAX(CASE WHEN p.type = 'Out' THEN p.PunchTime ELSE NULL END ) AS LatestOUt FROM Punches p
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
You can’t efficiently select multiple aggregates in vanilla LINQ to Objects. You can perform multiple queries, of course, but that may well be inefficient depending on your data source.
I have a framework which copes with this which I call ‘Push LINQ’ – it’s only a hobby (for me and Marc Gravell) but we believe it works pretty well. It’s available as part of MiscUtil, and you can read about it in my blog post on it.
It looks slightly odd – because you define where you want the results to go as ‘futures’, then push the data through the query, then retrieve the results – but once you get your head round it, it’s fine. I’d be interested to hear how you get on with it – if you use it, please mail me at skeet@pobox.com.