I am trying to convert a Dataset to a List of Object.
Here is what I have tried:
List<FundPerformanceRecord> FundPerformanceRecordList
= ds.Tables[0].AsEnumerable()
.Select(x => new FundPerformanceRecord
{
FundCode = x.Field<string>("FUND_CODE"),
OneMonth = x.Field<decimal>("ROR1MTH"),
ThreeMonth = x.Field<decimal>("ROR3MTH")
})
.ToList();
The class FundPerformanceRecord has the properties defined as Nullable Decimal.
[DataMember]
public string FundCode;
[DataMember]
public decimal? OneMonth;
[DataMember]
public decimal? ThreeMonth;
I am getting the following error message if any Cell value in the dataset has null value.
System error - Cannot cast DBNull.Value to type 'System.Decimal'. Please use a nullable type.
How can I resolve this issue ?