Reputation: 23941
I know that if you query a linq-to-sql record (ie row in DB/object) with a null field, then linq to SQL will allow you to access the null value without a null reference exception, like this: Dim myValue as String = myRecord.Nullfield
.
But I WANT to query records where the field in the underlying DB is null.
How do I do that with LINQ?
(From l In myDB.myTable Where l.Program.Equals(DBNull.Value) Select l).Count //Unexpected type code: DBNull
What is the syntax that I am looking for?
Upvotes: 0
Views: 1200
Reputation: 4173
See null semantics mismatching article on MSDN. Generally, you can use either
(From l In myDB.myTable Where l.Program.Equals(null) Select l).Count
or
(From l In myDB.myTable Where l.Program == null Select l).Count
Upvotes: 0
Reputation: 171236
Use == null
(or whatever the VB.NET equivalent is). No more DBNull
. Yay!
Upvotes: 2