Hi all
This is probably pushing the boundaries of Linq-to-Sql a bit but given how versatile it has been so far I thought I'd ask.
I have 3 queries that are selecting identical information and only differ in the where clause, now I know I can pass a delegate in but this only allows me to filter the results already returned, but I want to build up the query via parameter to ensure efficiency.
Here is the query:
from row in DataContext.PublishedEvents
join link in DataContext.PublishedEvent_EventDateTimes
on row.guid equals link.container
join time in DataContext.EventDateTimes on link.item equals time.guid
where row.ApprovalStatus == "Approved"
&& row.EventType == "Event"
&& time.StartDate <= DateTime.Now.Date.AddDays(1)
&& (!time.EndDate.HasValue || time.EndDate.Value >= DateTime.Now.Date.AddDays(1))
orderby time.StartDate
select new EventDetails
{
Title = row.EventName,
Description = TrimDescription(row.Description)
};
The code I want to apply via a parameter would be:
time.StartDate <= DateTime.Now.Date.AddDays(1) &&
(!time.EndDate.HasValue || time.EndDate.Value >= DateTime.Now.Date.AddDays(1))
Is this possible? I don't think it is but thought I'd check out first.
Thanks