0

I have this linq query request as:

  var test = (...
                where ...
                   && test.SL.Any(line =>
                        line.ServiceCode == serviceCode
                        && line.DateOfServiceStart >= dateOfServiceStart
                        && (line.DateOfServiceEnd == null || line.DateOfServiceEnd <= dateOfServiceEnd)
                     )
    select test).Distinct();

The type of line.DateOfServiceEnd is DateOnly, the value of the current result of this date is: 4/1/2024, and the dateOfServiceEnd parameter is: 12/1/2024, but it's returning results! Its supposed not to return results because 12/1/2024 is > than 4/1/2024, why is it returning results?

3
  • try to make code to compare as datetimes: DateTime.Parse(line.DateOfServiceStart) >= DateTime.Parse(dateOfServiceStart) Commented Jul 4 at 2:00
  • 3
    line.DateOfServiceEnd <= dateOfServiceEnd so replacing with values gets 4/1/2024 <= 12/1/2024 which is true what exactly is the question? Did you perhaps want > not <= ? Commented Jul 4 at 2:24
  • Jesus Christ! . Thanks @Charlieface
    – Jesus
    Commented Jul 4 at 2:51

0