I got a local List<DateInterval> where DateInterval is:
internal class DateInterval{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
I want to get all the events on the database that matches at least one of the DateInterval.
Ideally I’ll do something like:
var query = from _event in db.GetTable<Event>()
where dates.Any(d => d.StartDate <= _event.Date && d.EndDate > _event.Date)
select _event;
But I get the following exception:
Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator
Since the .Contain() method only accept exact results instead of timestamps, is there a way to achieve the desired results?
Your basic option here is to materialize the query from the database and then perform the comparison against the list in memory.
Obviously, the more filtering you can perform at the DB in order to pull less results into memory, the better, but in this case, your options are limited.
*The evaluation is still deferred until you use the results of the query, but the filtering from the additional
Wherewill happen in memory, the portion beforeAsEnumerable()will occur at the database.