title: Filtering across multiple Dynamics entities in Common Data Service
body: <p>I'm trying to query our Dynamics 365 CRM through the Common Data Service / Microsoft Dataverse. I can manage this when I need to just filter on fields that exist within the entity type I'm searching. But I also need to filter on a different linked entity.</p>
  <p>So far I can query on the contact entity just fine:</p>
  <pre><code>var contacts = svc.Get(&quot;contacts?&quot; +
       &quot;$select=firstname,lastname,address1_name,address1_line1,&quot; +
       &quot;address1_postalcode,emailaddress1,statecode,_parentcustomerid_value&amp;&quot; +
       $&quot;$filter=contains(firstname,'{firstName}') and &quot; +
       $&quot;contains(lastname, '{lastName}')&quot;
      , formattedValueHeaders);
  </code></pre>
  <p>And this returns a list of contacts which match the filter.</p>
  <p>However, I also need to filter on the Account Name that the contact is linked to. If I had the AccountId value then I could do this by adding <code>$&quot;contains(_parentcustomerid_value, '{accountId}')&quot;</code> to the filter. But I can't use this as the input data I'm receiving to query on is the name of the account and not an Id value.</p>
  <p>Any ideas on how to do this?</p>
  <p>Currently, the only way I can see is to use my existing query, then to loop through each contact and check the returned account name in the response, and if this matches then in effect I've filtered it. But I would prefer to be able to have the whole filter all in a single query.</p>