Matthis Kohli Matthis Kohli - 8 months ago 30 Question

VB.NET LINQ Method Syntax disallows implicit conversions from 'Boolean?' to 'Boolean'

I run into trouble when learning more about the Entity Framework and LINQ.

I am trying to find values from a database that match a specific date.

I have 1.250.000 entries and 36300 of them are from a specific date.

I am using plain old SQL until now and want to practice LINQ to refactor my application to work with the EF.

Can you tell where my mistake is?

The second way works but takes a lot of time ~15 sec

enter image description here



Where(Function(d) d.ExportedDate.HasValue AndAlso d.ExportedDate.Value = exportDate) 

On this way you select only rows where the nullable column ExportedDate is not null and where it equals the given date. ExportedDate.Value returns Date as opposed to d.ExportedDate which is a Date?. If you compare a Date? with a Date you get a Boolean? as result(not a Boolean), because Nothing means undefined.

This is an interesting difference to C#, related: Why is there a difference in checking null against a value in VB.NET and C#?

To fix the next error: append ToList to create a list.