Matthis Kohli
Matthis Kohli

Reputation: 1995

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

Upvotes: 0

Views: 436

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460098

Try:

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.

Upvotes: 4

Related Questions