title: "The value passed for ConditionOperator.In is empty" with ConditionExpression using ConditionOperator.In against an empty array operand
body: <p>I have some code as follows:</p>
  
  <pre><code>    QueryExpression qxEmpty = new QueryExpression("systemuser");
      object[] guids = (new Guid[] { }).Cast&lt;object&gt;().ToArray();
      ConditionExpression c = new ConditionExpression("systemuserid", ConditionOperator.In, guids);
      qxEmpty.Criteria.AddCondition(c);
      EntityCollection ecEmpty = service.RetrieveMultiple(qxEmpty);
  </code></pre>
  
  <p>It fails on the last line with a FaultException:  </p>
  
  <blockquote>
    <p>The value passed for ConditionOperator.In is empty</p>
  </blockquote>
  
  <p>If I initialize the <code>guids</code> variable to contain one or more valid guids existing in the target CRM, I get the expected result.  </p>
  
  <p>So why does RetrieveMultiple throw an exception when I have a condition that asks whether a value is a member of the empty set? The condition should evaluate to false and RetrieveMultiple should return an empty EntityCollection, not throw an exception, shouldn't it?</p>
  
  <p>MSDN seems to suggest it's some problem with the method overloading on ConditionExpression constructor, and to make sure that the appropriate object type is used, but as far as I can tell I'm doing it properly, passing an array of objects:
  <a href="https://msdn.microsoft.com/en-us/library/gg334419(v=crm.7).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/gg334419(v=crm.7).aspx</a></p>
  
  <p>I'm using version 7.1.0.1085 of the Microsoft.Xrm.Sdk</p>
  
  <p>Edit:  I guess I'm not asking the right question. How do I pass an empty set to ConditionExpression for use with ConditionOperator.In? </p>
  
  <p>Edit 2:
  Okay, here's the SQL I'm trying to translate to QueryExpression.</p>
  
  <pre><code>SELECT *
  FROM SystemUser
  WHERE SystemUserId IN
  (
     SELECT SystemUserid
     FROM SystemUser
     WHERE X=Y
  )
  </code></pre>
  
  <p>I've translated this roughly as follows:</p>
  
  <pre><code>QueryExpression qxEmpty = new QueryExpression("systemuser");
  object[] guids = getGuids(); // calls a method that executes the subquery
  ConditionExpression c = new ConditionExpression("systemuserid", ConditionOperator.In, guids);
  qxEmpty.Criteria.AddCondition(c);
  EntityCollection ecEmpty = service.RetrieveMultiple(qxEmpty);
  </code></pre>
  
  <p>The problem with the above is it fails when the subquery has no values. In SQL, it doesn't fail, it gives me an empty set, which is what I want as a result of the QueryExpression.  </p>
  
  <p>Edit 3:<br>
  Oops, I suddenly realized why this is a stupid question. Since CRM doesn't support subqueries, and I have to do this in two separate queries anyway, I might as well not do the second query when the list is empty, because I already know the result and so shouldn't spend the resources.  So although it might seem more elegant to support passing an empty array, in fact the exception is a nice signal for me to add the explicit checks in the code.</p>