toptensoftware/PetaPoco — pull request #174 by Chri-s (2013-12-10 12:42:52+00:00)
Title: Added support for DBNull in ExecuteScalar

If SqlCommand.ExecuteScalar() returns DBNull.Value and the return type T of ExecuteScalar is nullable, an InvalidCastException is thrown.
This patch handles DBNull.Value the same way as null.

This happens for example if ExecuteScalar("SELECT MAX(id) FROM empty_table") is queried on an empty table.