title: Raven DB LINQ Where->Any Query not working
body: <p>I'm getting a weird (non-)result from Raven DB.</p>
  
  <p>I'm running the latest stable build, v2.5.2666, on both the client and the server.</p>
  
  <p>What I want to retrieve is "the first DeployProject document who contains a Component object whose Id value is 'x'".</p>
  
  <p>So the first thing I tried is:</p>
  
  <pre><code>var project = _documentSession.Query&lt;DeployProject&gt;()
        .FirstOrDefault(i=&gt;i.ComponentList.Any(j=&gt;j.Id == componentId));
  </code></pre>
  
  <p>But that returned null, even though I know the data is correct.  To verify I'm not crazy, I added a .ToList() to middle, so it will pull out all of the documents into memory query it there.</p>
  
  <pre><code>var project = _documentSession.Query&lt;DeployProject&gt;()
        .ToList()
        .FirstOrDefault(i=&gt;i.ComponentList.Any(j=&gt;j.Id == componentId));
  </code></pre>
  
  <p>And that DID work, so my logic and data is correct.  But of course it's really inefficient, the whole idea is that I only want to pull the single document that contains the relevant child record.  </p>
  
  <p>So there definitely seems to be an issue with how Raven is querying the index, since the data is definitely there, and I can retrieve it if I pull everything into memory and run the same LINQ query.</p>
  
  <p>My hope (fear?) was that the index was stale, so I told it to give me fresh data:</p>
  
  <pre><code>var project = _documentSession.Query&lt;DeployProject&gt;()
        .Customize(i=&gt;i.WaitForNonStaleResultsAsOfLastWrite())
        .FirstOrDefault(i=&gt;i.ComponentList.Any(j=&gt;j.Id == componentId));
  </code></pre>
  
  <p>But again I got null.  It seems that Raven is just not treating the LINQ statement the way that I would expect, i.e. the way that LINQ to objects would work.  I know that there canbe some differences, but this should be a pretty straightforward query that I would expect to work.</p>
  
  <p>Anyone have any ideas?  Am I missing something simple?</p>
  
  <p>EDIT: According to Raven's documentation, it seems like this should work without any adventurous indexing: </p>
  
  <p><a href="http://ravendb.net/docs/client-api/querying/using-linq-to-query-ravendb" rel="nofollow">http://ravendb.net/docs/client-api/querying/using-linq-to-query-ravendb</a></p>
  
  <blockquote>
    <p>Other than the Where clause, there are several other useful operators
    you could use to filter results.</p>
    
    <p>Any can be used on collections of objects (or primitive lists) in your
    entities to return only those who satisfies a condition. RavenDB also
    supports an In operator, to make reverse Any comparisons easier:</p>
  </blockquote>
  
  <pre><code>// Return only companies having at least one employee named "Ayende"
  IQueryable&lt;Company&gt; companies = from c in session.Query&lt;Company&gt;()
                                  where c.Employees.Any(employee =&gt; employee.Name == "Ayende")
                                  select c;
  </code></pre>