The following expression returns a contact - the whole contact with dozens of properties. This is fine but, ideally, I'd like the return to be the contact's id (contact.contactId) property only. How do I do this?
var assocOrg = Contacts.Where(x => x.ContactTypeID == 2 && x.OrganizationName == "COMPANY XYZ");
var result = Contacts.Where(x => ...)
.Select(x => x.ContactID);
or
var result = from x in Contacts
where x.ContactTypeID == 2 && x.OrganizationName == "COMPANY XYZ"
select x.ContactID;
If you want to get a single or first object matching your conditions , use this :
var result = Contacts.Where(x => ...)
.Select(x => x.ContactID).FirstOrDefault();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With