Framework Design Guidelines: System.DBNull


Continuing in our weekly blog post series that highlights a few of the new image[5]_thumb[2]_thumb[2]_thumbadditions to the Framework Design Guidelines 2nd edition.. This content is found in the Nullable<T> section of Chapter 8: Usage Guidelines. Pablo helps us out with some subtle details that might really come in handy.

AVOID using System.DBNull. Prefer Nullable<T> instead.

PABLO CASTRO

Nullable<T> is in general a better representation of optional database values. One thing to consider though is that while Nullable<T> gives you the ability to represent null values, you don’t get database null operational semantics. Specifically, you don’t get null propagation through operators and functions. If you deeply care about the propagation semantics, consider sticking with DBNull.

Comments (7)

  1. What's New says:

    Continuing in our weekly blog post series that highlights a few of the new additions to the Framework

  2. Carlo Kok says:

    null propagation is a language feature though, not a platform one. Our compiler (Delphi Prism) does do null propagation when using nullable types expressions.

  3. Thank you for submitting this cool story – Trackback from DotNetShoutout

  4. asdf says:

    an example of each would have been great

  5. Jerry Odom says:

    LINQ to SQL knocks out some of these issues right?    My dbml objects come over as Nullable.

  6. DDD/ALT.NET Casey has written a bunch more in his DDD series since my last update 4) DDD: There Is No Database 5) DDD: Command Query Separation as an Architectural Concept 6) DDD: Entities and Value Objects 7) DDD: Where is the Code? 8) DDD: Download