I find it better to use null, instead of DB null The reason is because, as you said, you're separating yourself from the DB world It is generally good practice to check reference types to ensure they aren't null anyway. You're going to be checking for null for things other than DB data, and I find it is best to keep consistency across the system, and use null, not DBNull In the long run, architecturally I find it to be the better solution.
I find it better to use null, instead of DB null. The reason is because, as you said, you're separating yourself from the DB world. It is generally good practice to check reference types to ensure they aren't null anyway.
You're going to be checking for null for things other than DB data, and I find it is best to keep consistency across the system, and use null, not DBNull. In the long run, architecturally I find it to be the better solution.
If you've written your own ORM, then I would say just use null, since you can use it however you want. I believe DBNull was originally used only to get around the fact that value types (int, DateTime, etc. ) could not be null, so rather than return some value like zero or DateTime. Min, which would imply a null (bad, bad), they created DBNull to indicate this.
Maybe there was more to it, but I always assumed that was the reason. However, now that we have nullable types in C# 3.0, DBNull is no longer necessary.In fact, LINQ to SQL just uses null all over the place. No problem at all.
Embrace the future... use null. ;-).
I think there are still some uses for DBNull. At least with sqlite I can test if a value returned by ExecuteScalar() is explicitly stored in the database or not. Consider Table foo(a int, be int); with a single row (1, null).
If we were to ExecuteScalar on a command "SELECT be FROM foo WHERE A = 1", it would return DBNull. Value (the row exists a null is stored). If I were to call ExecuteScalar on "SELECT be FROM foo WHERE A = 2" it would return null (no such row exists).
Presumably you could achieve the same result with a DataReader but I do appreciate the convenience. – fostandy Nov 29 '09 at 14:27 Interesting. While using an ORM for DB access, I don't often explicitly use ExecuteScalar in my code.
I usually end up retrieving full entity objects and looking at their values that way. So if the entity itself is null that's one thing, and if the value is null, that's something else. Just different ways of doing it.
I admit that ExecuteScalar is more efficient if you just need one single value. – jeremcc Dec 4 '09 at 17:25.
From the experience I've had, the . NET DataTables and TableAdapters work better with DBNull. It also opens up a few special methods when strongly typed, such as DataRow.
IsFirstNameNull when in place. I wish I could give you a better technical answer than that, but for me the bottom line is use DBNull when working with the database related objects and then use a "standard" null when I'm dealing with objects and . NET related code.
Hope this helps!
Use DBNull. We encouintered some sort of problems when using null. If I recall correctly you cannot INSERT a null value to a field, only DBNull.
Could be Oracle related only, sorry, I do not know the details anymore.
If you've written your own ORM, then I would say just use null, since you can use it however you want. I believe DBNull was originally used only to get around the fact that value types (int, DateTime, etc.) could not be null, so rather than return some value like zero or DateTime. Min, which would imply a null (bad, bad), they created DBNull to indicate this.
Maybe there was more to it, but I always assumed that was the reason. However, now that we have nullable types in C# 3.0, DBNull is no longer necessary. In fact, LINQ to SQL just uses null all over the place.
No problem at all. Embrace the future... use null.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.