How can I handle exceptions in a linq query? For example if I have the following query:
var query = (from d in GetLHDb().daily_average
where d.findnsave_site_id == fnsID
&& d.test_path_id == pathId
&& d.date > nTimesDays
&& d.date <= yesterday
select new
{
loadtime = d.loadtime,
created_at = d.date
}).ToArray();
for instance, how can i handle the null exception inside the query? I have searched online but a lot of them are for VB.
In your case, just like you would any other place in your code. Wrap your
.ToArray()in atry/catchblock. Although in your case I would just be more defensive and handle the null value properly.