Can I customize a strongly typed dataset to use nullable values?

If I have a strongly typed data table with a column for values ​​of type Int32

and that column allows null, then I get an exception if I do this for a row where the value is null:

int value = row.CustomValue;

      

Instead, I need to do this:

if (!row.IsCustomValueNull()) {
    int value = row.CustomValue;
    // do something with this value
}

      

Ideally, I would like to be able to do this:

int? value = row.CustomValue;

      

Of course, I could always write my own method, something like GetCustomValueOrNull

; but it would be preferable if the auto-generated property for the column itself just returned null. Is it possible?

+2


a source to share


1 answer


Unfortunately this is not supported.

However, you can create your own wrapper property like:



    public int? CustomValue {
        get { return IsCustomValueqlNull() ? new int?() : CustomValueSql; }
        set {
            if (value == null)
                SetCustomValueSqlNull();
            else
                CustomValueSql = value.Value;
        }
    }

      

Where CustomValueSql

is the actual name of the column.

+1


a source







All Articles