Convert DBNull values to null #26

daveclarke opened this Issue Mar 23, 2011 · 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 Apr 29, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment