Strongly typed dataset not generating Nullable<> type args in Add<tablename>Row method?

170 Views Asked by At

I've used DataSets for a long time, gotten to know them inside out, even to the extent that I've no problem editing the XML directly to overcome limitations of the designer when working some less-than-mainstream databases but I'm looking for a sense check on something here..

I'm nearly certain that in the past, when I've set a column datatype to be a primitive type like Int32, DateTime, Guid and also have declared AllowDbNull=true, that the code generated by the msdatasetgenerator has produced an Add<tablename>Row() that has had int? / DateTime? / Guid? in the arguments, so that null can be passed and internally, the dataset uses DBNull.Value etc when writing to the database etc

I've just generated a few datasets in the designer for VS2017 pro, and none of the primitive columns that are AllowDBNull=true, have a nullable argument in the Add<tablename>Row()

I don't have any old projects to had to double check at the moment; does anyone know if anything has changed with recent versions of the dataset generator that have knocked out the nullable arguments facility on the Add<tablename>Row method?

Edit: Here, Table is nullable DateTime, but DataSet throws an exception? Rob Rossney seems to be confirming what I thought was the case when he says:

Is particularly bad because typed data sets do use nullable types in some places - for instance, the AddRow() method for the table containing the nullable DateTime column described above will take a DateTime? parameter.

(Answers of "no, you're actually going crazy, AddRow() has never had nullables.. You're thinking of the other method BlahBlah()" are fine.. Even just "it has never supported this, you're going crazy" is also fine. Hopefully the actual answer is "you've forgotten to also set the ABC property on the DataColumn; it's that that makes the generator generate nullable arguments, not AllowDbNull=true"

Note that I'm not asking about setting the type of a DataColumn to be e.g Nullable - I know this cannot be done; but I'm convinced that for declared nullable primitive columns the generated code used to be helpful in some places, allowing a null to be passed and wrangling with it in the designer generated code.." )

0

There are 0 best solutions below