Get values between two dates
Although the answer from Heslacher is a really good one, here's also what you might do. Create two boolean variable to check for null on the model.ValidFrom and model.ValidTo:

bool modelValidFromIsNull = model.ValidFrom == null;
bool modelValidToIsNull = model.ValidTo == null;


Now, like Heslacher mentioned, place a guard to rule out if they are both null.

if (modelValidFromIsNull &amp;&amp; modelValidToIsNull) { return null; }


Now you can use these bool variables to do some magic. In the Where() clause of the query, use these flags to check or ignore the condition you want to apply. If the flag is true, the condition will be skipped and if it is false, the condition will be evaluated. A small example:

var numbers = new[] { 1, 2, 3, 4, 5, 6 };
var remaining = numbers.Where(x =&gt; false || x &gt; 3);


The variable remaining will now contain 4, 5 and 6. If you were to change that false to true, the variable remaining would contain all the numbers from the original source. [That's why you need the guard :) ]

Now you can apply this logic to your code. When the model.ValidFrom is not null, your variable modelValidFromIsNull will be false. This means that in the where clause the left part is false and the second part will be evaluated. The same goes for model.ValidTo.

This is the resulting code:

bool modelValidFromIsNull = model.ValidFrom == null;
bool modelValidToIsNull = model.ValidTo == null;

if (modelValidFromIsNull &amp;&amp; modelValidToIsNull) { return null; }

var result = dalList.Where(s =&gt; modelValidFromIsNull || DbFunctions.TruncateTime(s.ValidFrom) &gt;= dateFrom.Date)
                    .Where(s =&gt; modelValidToIsNull || DbFunctions.TruncateTime(s.ValidTo) &lt;= dateTo.Date);