I'm trying to add additional where clauses to a linq query depending on what variable results are passed to a function.
var allFeedback =
from f in _unitOfWork.Feedback.All()
join b in _unitOfWork.Bookings.All() on f.CourseBookingID equals b.CourseBookingID
join cb in _unitOfWork.CourseBookings.All() on f.CourseBookingID equals cb.CourseBookingID
where b.SiteID == siteID && b.Date >= fromDate && b.Date <= to && b.CancelledID == null
select f;
if (courseID > 0)
{
allFeedback.Where(f => f.CourseBooking.CourseID == courseID);
}
if (facilitatorID == 0)
{
allFeedback.Where(f => f.CourseBooking.FacilitatorID == null);
}
else if (facilitatorID > 0)
{
allFeedback.Where(f => f.CourseBooking.FacilitatorID == facilitatorID);
}
allFeedback.ToList();
I want to add the where clauses to the original query "allFeedback" but when the query is executed the additional clauses are ignored.
Is this possible?