I posted something about this a few years ago, but I'm wondering if it needs 'fixing' or if there's a reason it is the way it is.
Here's the code generated for a date field in a TypedView. The underlying database field is nullable, but the property type here is DateTime, so the only way to get Null in there is to call SetExpectedPaymentDateNull.
This is extremely cludgy in code, particularly when populating many properties in a TypeViewRow.
If the column is marked as Optional in the TypedView definition should this not be DateTime?
with a conditional setter such as
set { this[_parent.ExpectedPaymentDateColumn] = value ?? System.Convert.DBNull; }
?
I can use myNewRow["ExpectedPaymentDate"] = src.ExpectedPaymentDate ?? System.Convert.DBNull;
in my data transfer process but I hate using the string identifier for the column name.
Cheers,
Jason
public System.DateTime ExpectedPaymentDate
{
get { return IsExpectedPaymentDateNull() ? (System.DateTime)TypeDefaultValue.GetDefaultValue(typeof(System.DateTime)) : (System.DateTime)this[_parent.ExpectedPaymentDateColumn]; }
set { this[_parent.ExpectedPaymentDateColumn] = value; }
}