I have a model where Person has 0, 1 or 2 Contact objects.
Contact information home (contact_type is “h”) and contact information for work (contact_type is “w”).
Is there a way to check that the Contact object with contact_type == "h" exists when selecting street name? Right now I’m getting a null exception if the Contact object does not exist.
from m in persons
select new
{
Id = m.id,
Name = m.surname,
Address = m.Contacts.Where(c => c.contact_type == "H").SingleOrDefault().streetname
};
How about:
or:
which could also be written (perhaps more clearly):