I initially wanted to quickly select certain records (using a Linq
qry) which match a default date condition (01/01/0001
) -
var defDates = (from rec in myRecords where rec.myDate == System.DateTime.MinValue select rec.myDate);
and then update those record(s) to a Null
value. However, since those returned records have only a get
, it means they are read-only (makes sense since I'm using Linq).
So the best I could come up with is a c# foreach
which will catch default dates and sets to Null (i.e. I'm exporting to Excel
via Aspose.cells
, so I need those cell values to just be blank):
foreach (myExportClass rec in myRecords)
{
if (rec.myDate == System.DateTime.MinValue)
{
rec.myDate = null;
}
};
Okay, this works, and exports the required Null value(s) to Excel (a blank cell, actually).
However, the question is: could I find a more efficient way of handling this default date scenario ? Seems to me that a foreach() may waste resources if there are several thousand records coming back.
Fyi: the records are coming back from the backend this way, so I need to deal with this in c#.
thanks in advance