LINQ query that filters elements from a list of object I have two lists of objects Person and PersonResult. Both are linked through the property PersonId. I need to create a filter for the list of PersonResult that meet certain criteria for the Person (e.g. Person.Gender == "female").

Im currently using the following LINQ query to achieve this:

PersonResultList = PersonResultList.Where(pr =&gt; 
    PersonList.FirstOrDefault(p =&gt; pr.PersonId == p.PersonId) != null &amp;&amp; 
    PersonList.FirstOrDefault(p =&gt; pr.PersonId == p.PersonId).Gender == "female");


This works apparently well, however, I must iterate twice through PersonList to check if the person exist and its gender. Is there a more elegant way to achieve this?
You can simply combine the conditions inside the FirstOrDefault() like  

PersonResultList = PersonResultList
    .Where(pr =&gt; PersonList
                    .FirstOrDefault(p =&gt; pr.PersonId == p.PersonId 
                                         &amp;&amp; p.Gender == "female") != null );  


Because I only changed your existing code, it didn't came to my mind what Nikita Brizhak commented here .  


  You should probably use Any instead of FirstOrDefault  


So let us change the code to  

PersonResultList = PersonResultList
        .Where(pr =&gt; PersonList
                        .Any(p =&gt; pr.PersonId == p.PersonId 
                              &amp;&amp; p.Gender == "female")); 


This is based on the assumption that for each entry in the first list there will be only one entry in the second list.