title: Dynamics CRM 2011 - Getting set of N:1 related entities with QueryExpression
body: <p>I'm working on a custom web service for a CRM 2011 deployment, and I'm now making an overview which relates to some of our entities. We have a custom <code>product</code> entity with details such as the product name and category, and we have an <code>agreement</code> entity, which links the <code>product</code> to the customer and contains product details specific to that customer. <code>agreement</code> and <code>product</code> have an N:1 relationship.</p>
  
  <p>I'm now making an overview page that will be displayed on the customer page in CRM, which should display all <code>agreement</code>s on that customer. For this display, I also need to retrieve some information about the <code>product</code>s these agreements link to, which will be used to group the <code>agreement</code>s on the overview page. I've been unable to find any relevant/specific examples on this, and I'm stuck trying to find a feasible way of querying for the data I need.</p>
  
  <p>The way I imagine it, I would like to use two queries to get the required data. First, a query that gets all the <code>agreement</code>s on the customer. Then pass this list to a second query, which returns all the <code>product</code>s that intersect the first list. Is this possible using a <code>QueryExpression</code>, or do I need to loop over the <code>agreement</code> list and run a separate query for each individual association? I'd prefer to avoid <code>FetchXML</code> if possible.</p>