<p>We have our own ORM we use here, and provide strongly typed wrappers for all of our db tables. We also allow weakly typed ad-hoc SQL to be executed, but these queries still go through the same class for getting values out of a data reader.</p>

<p>In tweaking that class to work with Oracle, we've come across an interesting question. Is it better to use DBNull.Value, or null? Are there any benefits to using DBNull.Value? It seems more "correct" to use null, since we've separated ourselves from the DB world, but there are implications (you can't just blindly <code>ToString()</code> when a value is null for example) so its definitely something we need to make a conscious decision about.</p>

[{'answer_id': 12848, 'author': 'Dillie-O', 'author_id': 71, 'author_profile': 'https://Stackoverflow.com/users/71', 'pm_score': 2, 'selected': False, 'text': '<p>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.</p>\n\n<p>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.</p>\n'}, {'answer_id': 12854, 'author': 'John Smithers', 'author_id': 1069, 'author_profile': 'https://Stackoverflow.com/users/1069', 'pm_score': 1, 'selected': False, 'text': '<p>Use <code>DBNull</code>.<br>\nWe encouintered some sort of problems when using null.<br>\nIf I recall correctly you cannot INSERT a null value to a field, only DBNull.<br>\nCould be Oracle related only, sorry, I do not know the details anymore.</p>\n'}, {'answer_id': 12935, 'author': 'Dan Herbert', 'author_id': 392, 'author_profile': 'https://Stackoverflow.com/users/392', 'pm_score': 5, 'selected': True, 'text': "<p>I find it better to use null, instead of DB null.</p>\n\n<p>The reason is because, as you said, you're separating yourself from the DB world.</p>\n\n<p>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 <code>DBNull</code>.</p>\n\n<p>In the long run, architecturally I find it to be the better solution.</p>\n"}, {'answer_id': 12991, 'author': 'jeremcc', 'author_id': 1436, 'author_profile': 'https://Stackoverflow.com/users/1436', 'pm_score': 3, 'selected': False, 'text': "<p>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 <em>be</em> null, so rather than return some value like zero or DateTime.Min, which would <em>imply</em> 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. ;-)</p>\n"}]
['https://Stackoverflow.com/questions/12836', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/489/']