Accepted answer

You could check if one of both are null:

List<ApplicantList> applicants = appRegistrations
    .Select(ar => c.Participant == null || c.Participant.PartnerType == null 
                  ? "" : c.Participant.PartnerType.PartnerTypeName)
    .Select(str => new ApplicantList { PartnerType = str })


When you construct the objects such as Participant, make sure that the properties are never null. Think if null is a valid value for a Participant? If not then you should never allow it to be null. Take a constructor parameter and add a guard clause to check for nulls. Otherwise initialize them to a default value.

Also, see NULL Reference Pattern.


You can shorten it a little bit:

PartnerType = c.Participant != null && c.Participant.PartnerType != null 
            ? c.Participant.PartnerType.PartnerTypeName 
            : ""

Related Query

More Query from same tag