I have an Extension method that does the following:
public static bool Between(this DateTime target, DateTime startDate, DateTime endDate)
{
return target >= startDate && target <= endDate;
}
and I can call it like this
if (expectedDate.Between(minDate, maxDate)) { do code }
I'm now trying to use this in a Linq/Lambda expression like
return list.Where(item => targetDate.Between(item.StartDate, item.EndDate));
OR if (!list.Any(pp => targetDate.Between(pp.StartDate, pp.EndDate)))
and I get the following error in runtime:
LINQ to Entities does not recognize the method 'Boolean Between(System.DateTime, System.DateTime, System.DateTime)' method, and this method cannot be translated into a store expression.
But this is fine
if (!list.Any(item => targetDate >= item.StartDate && quoteDate.EventDate <=item.EndDate)))
I would like to have a common method to call. What are my options?