Search code examples
restdynamics-crm-2011odatadynamics-crmdynamics-crm-2013

Dynamics CRM REST oData endpoint support for All and Any


Just wondering if current REST endpoint (2013) supports Any or All for filtering based on child entity:

http://localhost/xrmservices/2011/OrganizationData.svc/AccountSet?$select=Name&$expand=lead_parent_account&$filter=lead_parent_account/any(x:x.City eq '')

Comes back with: No property 'any' exists in type 'System.Collections.Generic.IEnumerable`1[[Microsoft.Xrm.Sdk.Entity, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]' at position 20.


Solution

  • The OData endpoint only returns entities, you cannot perform boolean queries such as IEnumerable<T>.Any()/.All()1.

    Everything needs to start from data: a query similar to yours to grab the relevant entities might look like this:

    /AccountSet?$select=Name&$expand=lead_parent_account&$filter=lead_parent_account/City eq ''
    

    If you get a non-empty set of results, then the equivalent .Any() is true.

    Checking .All() is nasty: the closest way I can think of would be checking if the query has returned all records from AccountSet (gonna take a while if you have thousands of records, also remember that results are capped at capped at 5000 per query, and paged if there are more).

    (1: Of course, if one performs a QueryExpression in code, the results can be LINQ-ed at will, since you're no longer relying on the quite limited LINQtoCRM query provider, but it's not very relevant here)