Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Convert DBNull values to null #26

daveclarke opened this Issue · 2 comments

3 participants


When returning data from a Query, is it possible to convert DBNull values to null so can use ?? operator?

    public IEnumerable<dynamic> Query(string sql, params object[] args)
        using (var conn = OpenConnection())
            var rdr = CreateCommand(sql, conn, args).ExecuteReader(CommandBehavior.CloseConnection);
            while (rdr.Read())
                var e = new ExpandoObject();
                var d = e as IDictionary<string, object>;
                for (var i = 0; i < rdr.FieldCount; i++)
                    d.Add(rdr.GetName(i), DBNull.Value.Equals(rdr[i]) ? null : rdr[i]);
                yield return e;

I agree with you


It certainly is. Would love a patch.

@robconery robconery closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.