I have this LINQ query:
var resourcePlanningInWeek = resourcePlanning.Where(rp => rp.PlanDate >= dateFrom && rp.PlanDate <= dateTo);
var holidays = new HolidayManager().GetByPeriod(dateFrom, dateTo);
var resourcePlanningExcludedHolidays= resourcePlanningInWeek.Where(rpiw => ( holidays.Where(h => h.HolidayDate = rpiw.PlanDate).Count = 0))
When executed, I get following error:
Cannot implicitly convert type ‘DateTime’ to ‘bool’
Somewone know why?
==instead of=when you want to make a comparison. That’s relevant at two places in the last line.Countis missing the parentheses.However, there is a better way of writing this:
This is better, because:
holidaysas soon as the condition is true the first time.Count()always enumerates the complete list.An even better approach would be to use a
HashSet<DateTime>: