How do I hand LINQ to DataSet when a value is DBNull?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am attempting to write a LINQ to Dataset query but unsure of how to deal with any DBNULL values. My code looks like the following:var requestDetailList =
from r in ds.Tables[0].AsEnumerable()
join s in ds.Tables[1].AsEnumerable()
on new { RFD = r.Field<long>("RequestFileDetailID"), ASE = (int)AlertServiceRequestTypeID.ClubUtilizationThreshold }
equals
new { RFD = s.Field<long>("AlertServiceEnrollmentRequestID"), ASE = s.Field<int>("AlertServiceEnrollmentTypeID") }
into ClubSettings
from cs in ClubSettings.DefaultIfEmpty()
select new AMEnrollRequestInfo_EX
{
FileDetailID = Convert.ToInt32(r.Field<long>("RequestFileDetailID")),
EnrollmentID = r.Field<int>("EnrollmentID"),
AccountNumber = r.Field<string>("CustomerAcctID"),
CBFCtlNumber = r.Field<int>("cbf_ctl_number"),
CustNumEcho = r.Field<int>("Custnum").ToString(),
SSN = r.Field<string>("SSN"),
LastName = r.Field<string>("LastName"),
FirstName = r.Field<string>("FirstName"),
MiddleInitial = r.Field<string>("MiddleInitial"),
Generation = r.Field<string>("Generation"),
StreetNumber = r.Field<string>("StreetNumber"),
StreetDirection = r.Field<string>("StreetDirection"),
StreetName = r.Field<string>("StreetName"),
City = r.Field<string>("City"),
State = r.Field<string>("State"),
Zip = r.Field<string>("Zip"),
PIN = r.Field<string>("PIN"),
EnrollStatus = r.Field<Int16>("StatusID").ToString(),
CustNum = r.Field<int>("Custnum"),
ProductID = Convert.ToInt32(r.Field<Int16>("ProductID")),
StatusID = Convert.ToInt32(r.Field<Int16>("StatusID")),
StepID = Convert.ToInt32(r.Field<Int16>("StepID")),
ClubUtilizationLimit = (cs == null) ? string.Empty : cs.Field<string>("AlertServiceEnrollmentSettingValue")
};

View the full article
 
Back
Top