0

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

Matthis Kohli
  • 1,877
  • 1
  • 21
  • 23

1 Answers1

4

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.

Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • Thank you for the clarification of the Date? and Boolean?. Never heard of it until now. That will help me in future. Makes totally sense now. +1 – Matthis Kohli May 12 '16 at 13:01