Question

Is it possible to create a fetchxml/query expression/LINQ expression in Dynamics CRM 2013 that will return all parent entities that don't have a child entity with an attribute set to a specific value?

For example, can we retrieve all accounts which don't have an associated contact named Bob Smith?

It's easy to do this in SQL as shown below, but I'm trying to avoid having to go down that route unless absolutely necessary:

 select name 
 from filteredaccount a 
 left outer join filteredcontact c on a.accountid = c.accountid and c.fullname = 'Bob Smith'
 where c.contactid is null
Was it helpful?

Solution

As far as I know left outer join is now supported. Not sure regarding your query but you always can use sql2fetch website:

<fetch mapping="logical">
  <entity name="account">
    <attribute name="name" />
    <filter>
      <condition attribute="contactid" operator="null" />
    </filter>
    <link-entity name="contact" to="accountid" from="accountid" alias="c" link-type="outer">
      <filter>
        <condition attribute="fullname" operator="eq" value="Bob Smith" />
      </filter>
    </link-entity>
  </entity>
</fetch>

Here are websites that describes left outer joins in Fetch: http://msdn.microsoft.com/en-us/library/dn531006.aspx http://www.powerobjects.com/blog/2013/11/07/perform-left-join-fetchxml-display-results-crm-2013/ http://gonzaloruizcrm.blogspot.com/2014/02/all-about-outer-join-queries-in-crm.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top