The first expression retrieves a contact’s ID using another identifying value. The second expression retrieves the whole contact using a contact ID. It seems like I should be able to merge these two statements into one but I’m struggling too much (tired, stressed, making dumb mistakes, etc.). The two statements work and I get the result I need but I feel it could be cleaner and probably a single expression.
Thanks for everyone’s help!
var contactId = DAL.dc.ContactMrns.Where(cm => cm.MRN == recipient.MRN)
.Select(x => x.ContactId)
.First();
var contact = DAL.dc.Contacts.Where(c => c.ContactID == contactId).First();
Well, it looks like that’s probably a join:
Note that you might want to use
Single()instead ofFirst()to make it clear that you really do only expect a single result.Another option is to use the Single overload which takes an expression: