Account:
Id|Contact1|Contact2
Contact:
Id|status
I need a LINQ query that returns all of the accounts where contact1 and contact2 do not have a certain status.
var query = from a in accounts
join c1 in contact on a.contact1 equals c1.id
join c2 in contact on a.contact2 equals c2.id
where c1.status != 1 && c2.status != 1
select new {a.id}
I'm struggling with the logic. Clearly this isn't going to work, and doesn't. Just not sure how to join two tables on one in linq.
EDIT: I discovered my issue is in most cases contact2 is null. I need some sort of conditional join that only occurs if a.contact2 is not null.
To clarify, the logic I'm attempting to achieve is: Retrieve all accounts where contact1 status does not equal 1. If contact1 == 1, check if contact2 == 1. If contact2 != 1 retrieve the account.
Running into issues because contact2 on the account is not always populated. When it's null, nothing is retrieved by my original query.