This is not about DBNull vs Null. I understand the difference.
What I would like to know is if I am using Linq, say to access a User.EmailAddress, then checking User.EmailAddress == null is the same as User.EmailAddress == DBNull correct?
My reasoning is that the absence of data in the database results into Linq not generating an object reference, which then means that null is in fact equivalent to DBNull when used with Linq.
Is my reasoning correct or not?
Do not confuse the notion of null in an object-oriented programming language with a DBNull object. In an object-oriented programming language, null means the absence of a reference to an object. DBNull represents an uninitialized variant or nonexistent database column.
DBNull represents a nonexistent value returned from the database. In a database, for example, a column in a row of a table might not contain any data whatsoever. That is, the column is considered to not exist at all instead of merely not having a value. A DBNull object represents the nonexistent column.
You shouldn't use DBNull with LinqToSql. The point is Language Integration, and so one concept or name for null
will suffice.
Here's the select statement that works in LINQ to SQL for Visual Basic. I assume it will be the same in C#.
User.EmailAdress.Equals(Nothing)
For example:
Dim EmptyEmailAddressEntries = From User in DC.Users _
Where User.EmailAddress.Equals(Nothing) select User
Will give you all the Users that have nothing in the email address. To check for entries with space " " characters only add
Or
User.EmailAddress = ""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With