title: Enumerable.Any() is very Slow on Large Linq Data Set
body: <p>I'm running code like this:</p>
  
  <pre><code>var somethings = db.Somethings.Select(s =&gt; new SomethingViewModel
  {
      Id = s.Id,
      Name = s.Name,
      IsActive = s.IsActive
      SubSomethings = s.SubSomethings.Select(ss =&gt; new SubSomethingViewModel
      {
          Id = ss.Id,
          Name = ss.Name,
          IsActive = ss.IsActive
      }).Where(wss =&gt; wss.IsActive)                        
  }).Where(ws =&gt; ws.IsActive &amp;&amp; (ws.SubSomethings.Any())) //remove elements if no SubSomethings
  .ToList();
  </code></pre>
  
  <p>As you can see, this is a one to many relationship. There are a list of SubSomethings in a Something. If I take out the  &amp;&amp; (ws.SubSomethings.Any()), I get a very fast list returned.</p>
  
  <p>But, I want to only include in the list the Somethings that have at least one SubSomething. I also tried the following and got the same horrible efficiency:</p>
  
  <pre><code>var somethings = db.Somethings.Select(s =&gt; new SomethingViewModel
  {
      Id = s.Id,
      Name = s.Name,
      IsActive = s.IsActive
      SubSomethings = s.SubSomethings.Select(ss =&gt; new SubSomethingViewModel
      {
          Id = ss.Id,
          Name = ss.Name,
          IsActive = ss.IsActive
      }).Where(wss =&gt; wss.IsActive)                        
  }).Where(ws =&gt; ws.IsActive)
  .ToList(); //this finishes very quickly
  
  var somethings2 = somethings.Where(s =&gt; s.SubSomethings.Any()).ToList(); //This is where the code bogged down
  </code></pre>
  
  <p>How can I re-write my query to get the bogging down code to be much faster? One thing to note: This works just fine with one or two records. When I hit >8000 records, it takes at least four minutes.</p>
  
  <p>Here is the Index I created on the SubSomething table for the foreign Key of SomethingId, which corresponds to Something.Id</p>
  
  <pre><code>CREATE NONCLUSTERED INDEX [IX_SubSomething_SomethingId] ON [dbo].[SubSomething]
  (
      [SomethingId] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
  GO
  </code></pre>
  
  <p>Here is the foreign key creation of SubSomething.SomethingId:</p>
  
  <pre><code>ALTER TABLE [dbo].[SubSomething]  WITH CHECK ADD  CONSTRAINT [FK_SubSomething_Something_SomethingId] FOREIGN KEY([SomethingId])
  REFERENCES [dbo].[Something] ([Id])
  GO
  
  ALTER TABLE [dbo].[SubSomething] CHECK CONSTRAINT [FK_SubSomething_Something_SomethingId]
  GO
  </code></pre>