title: how to compare values from a list in Linq to Entity (any / contains)
body: <p>There is a list, <code>policiesToDelete</code> of entity class, <code>MonitoringRelations</code>. Out of this list I have selected two elements and construed a new list:</p>
  
  <pre><code>var policyKeysToDelete = policiesToDelete
      .Select(r =&gt; new {r.PolicyId, r.GroupId})
      .ToList();
  </code></pre>
  
  <p>Now, I have a query where I want to compare elements from <code>policyKeysToDelete</code> list.</p>
  
  <pre><code>var objectsToDelete = (from p in storageContext.MonitoringRelations
                         where policyKeysToDelete
                              .Any(x =&gt; x == new {p.PolicyId, p.GroupId})
                         select p)
                         .ToList();
  </code></pre>
  
  <p><strong>The problem</strong>: the query above throws this exception:</p>
  
  <p><code>NotSupportedException: Unable to create a constant value of type 'Anonymous type'. Only primitive types or enumeration types are supported in this context.</code></p>
  
  <p>I have tried changing the anonymous list to a <code>list&lt;tuple&lt;PolicyId, GroupId&gt;&gt;</code> , but that also didn't help, throwing the almost same exception. I tried using <code>Contains</code> in place of <code>Any</code> but that also didn't help.</p>
  
  <p>Any idea how can I solve this problem?</p>