Title: Can I configure a strongly typed data set to use nullable values?
Tags: .net;datatable;strongly-typed-dataset;datacolumn
Question: If I have a strongly typed data table with a column for values of type Int32, and this column allows nulls, then I'll 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'd be preferable if the property auto-generated for the column itself simply returned a nullable. Is this possible?

Here is the accepted answer: Unfortunately, this is not supported.
However, you can make your own wrapper property, like this:
public int? CustomValue {
get { return IsCustomValueqlNull() ? new int?() : CustomValueSql; }
set {
if (value == null)
SetCustomValueSqlNull();
else
CustomValueSql = value.Value;
}
Where CustomValueSql is the actually column name.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 2.5', 'CreationDate': '2010:00:05/03/10', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<.net><datatable><strongly-typed-dataset><datacolumn>', 'Title': 'Can I configure a strongly typed data set to use nullable values?', 'ViewCount': 161, 'id': 2758761, 'user_AboutMe': '<p>Author of the blog <a href="https://philosopherdeveloper.com/" rel="nofollow noreferrer">The Philosopher Developer</a> and the open source libraries <a href="http://danieltao.com/lazy.js/" rel="nofollow noreferrer">lazy.js</a> and <a href="https://github.com/dtao/nearest-color" rel="nofollow noreferrer">nearest-color</a> (among others), and cohost of the podcast <a href="https://anchor.fm/spaceflix" rel="nofollow noreferrer">Spaceflix</a>.</p>\n<p>GitHub: <a href="https://github.com/dtao" rel="nofollow noreferrer">dtao</a><br />\nTwitter: <a href="https://twitter.com/dan_tao" rel="nofollow noreferrer">@dan_tao</a><br />\nSoundCloud: <a href="https://soundcloud.com/dantao" rel="nofollow noreferrer">dantao</a></p>\n<p>I’m the Head of Engineering for <a href="https://bitbucket.org/" rel="nofollow noreferrer">Bitbucket Cloud</a>. Previously I\'ve worked at Google, <a href="http://www.cardpool.com/" rel="nofollow noreferrer">Cardpool</a>, and <a href="http://www.thoughtworks.com/" rel="nofollow noreferrer">ThoughtWorks</a>.</p>\n', 'user_AccountId': 36964.0, 'user_DisplayName': 'Dan Tao', 'user_Reputation': 123356.0, 'user_Views': 8009.0, 'user_id': 105570.0}}