The Entity Manager will present all business entities in a common format, the Big-5 consultant raved, allowing any application within the enterprise to access the CRM system. That, and the bargain-basement rate of £1000/developer/day, made the Entity Manager-based CRM system an install sell to management. A year and a few million pounds later, Mike Barker's company was the proud owner of a somewhat-functioning, fairly buggy CRM system.

But none of this really impacted Mike; his group had nothing to do with the CRM system. That is, until his system was required to interface with the CRM. Fortunately, working with the Entity Manager wasn't too bad. It was simply XML-in, XML-out ...

In order to retrieve an EntitySet, you will need to create an EntityQuery and pass it to the EntityManager. An EntityQuery can request any number of different Entities to retrieve and will return zero or more of each type requested based on the parameters. The EntityQuery must be in the following format:

<EntityQuery>
  <Entity Name="{ENTITY_NAME}">
    <Fields>
      <Field Name="{FIELD_NAME}" Value="{FIELD_VALUE}" />
      <!-- ... More Fields ... -->
    </Fields>
  </Entity>
  <!-- ... More Entities ... -->
</EntityQuery>

But as he read further in the Entity Manager documentation, Mike learned the CRM was a bit more WTF than he thought ...

To query a date field over a range, the value of the query field must be exactly "{START_DATE}' OR {FIELD_NAME} BETWEEN '{START_DATE}' AND '{END_DATE}". For example, to retreive all ClientContacts from the month of April, 2003, simply use the following query:

<EntityQuery>
  <Entity Name="ClientContact">
    <Fields>
      <Field 
        Name="ContactDate" 
        Value="2003-04-01' OR ContactDate BETWEEN '2003-04-01' AND '2003-04-30"
      />
    </Fields>
  </Entity>
</EntityQuery>