title: How to match specific properties within two lists in c# using LINQ
body: <p>I am using Entity Framework for a home project.</p>
  
  <p>For the example, let's say I have two lists : A and B</p>
  
  <p>I need to be able to match the items in list A and B based on common properties between the two (Pick  all the houses that have the same Value and the same City in lists A and B)</p>
  
  <p>A House can have two properties in common in the two lists (say Value and City) but some other properties can be different (such as HouseId), so comparing objects does not return the proper match.</p>
  
  <p>I could do two nested foreach, but since the LINQ query is meant to query the database using EF, I need to do it using LINQ.</p>
  
  <p>This is what I did so far, but the match is not correct :</p>
  
  <pre><code>    public IEnumerable&lt;ApplicationUser&gt; GetMatchesForCurrentUser(ApplicationUser     currentUser)
      {
          var prematches = (from user in _memberRepository.All()
                            where user.Zone == currentUser.Zone &amp;&amp;
                                  user.Time == currentUser.Time &amp;&amp;
                                  user.HouseOfUser.Any(g =&gt; currentUser.HouseOfUser.Any(x =&gt; x.CityId == g.CityId))
                            select user).ToList();
  
          var matches = (from prematch in prematches
                         where prematch.HouseOfUser.Any(g =&gt; currentUser.HouseOfUser.Any(x =&gt; x.Value == g.Value))
                         select prematch).ToList();
  
          return matches;
      }
  </code></pre>