Substituting null fields in a Linq query

I have a Linq query that I use for date range filtering, which normally works fine but in the case of one set of results, the second date value is null ~80% of the time. This causes the query to return no results. I'm trying to figure out a way I can substitute the nulls with the current date just to allow the query to complete and return results. Here is an example:

var query = Contracts.GetContracts() .Where(h => (h.startdate.Date >= Convert.ToDateTime(fromdate))) .Where(h => (h.expdate.Date <= Convert.ToDateTime(todate))); 

In my case "todate" "expdate" is often NULL and that's what I'd like to replace on-the-fly

Ninja Edit: bonehead

by thedevilsmilkman via /r/csharp

Leave a Reply