I'm trying to convert this code from a stored procedure into a "LINQ to Entities" query:
select * from myTable
where venue_date + start_time <= @EndDate
and dateadd(minute, duration * 24 * 60, venue_date + start_time) >= @StartDate
As you can see there is some manipulation of dates. This sort of thing won't work because functions such as .AddHours()
are not supported:
where b.Venue_Date.Value.AddHours(b.Start_Time.Value.Hour) <= request.EndDate
Something like this won't work either. The error says something about not supporting constructors with parameters:
where new DateTime(b.Venue_Date.Value.Year, b.Venue_Date.Value.Month,
b.Venue_Date.Value.Day, b.Start_Time.Value.Hour, b.Start_Time.Value.Minute,
b.Start_Time.Value.Second) <= request.EndDate
It seems that the Entity Framework is VERY restrictive when dealing with dates. I guess I'll have to use a procedure. The next problem is figuring out how to make a procedure that can populate several related object collections.