Is there any way (through a extention mechanism?) to get the Sum() function to allways return 0.
My workaround now is to write like this, but I’m hoping there’s a better solution?
((int?)e.CampaignCodes.Sum(f => f.Enquiries.Count()) ?? 0),
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.
Your workaround there is a good one. Why don’t you write an extension method for IEnumerable similar to Sum called something like SumOrDefault. Then you could just reuse your extension method and you will not have to see the workaround.
Your extension method will be very simple and just use the exact code from your workaround.