title: Asp.Net Web Api - Returning 404 for IEnumerable<T> Get When null
body: <p>I am creating an API using the release version of Asp.Net Web Api.  I am trying to pass back the correct response code (404) if no results are found. </p>
  
  <p><strong>First Get Version (throws multiple enumeration error):</strong></p>
  
  <pre><code>public IEnumerable&lt;MyObjectType&gt; Get(int id, string format)
  {
      var db = new DbEntities();
  
      var result = db.pr_ApiSelectMyObjectType(store, id, format).AsEnumerable();
      if (result.Any())
      {
          return result;
      }
      var response = new HttpResponseMessage(HttpStatusCode.NotFound) 
          { Content = new StringContent("Unable to find any results") };
      throw new HttpResponseException(response);
  }
  </code></pre>
  
  <p><strong>Second Get Version (result is never null, so it always returns 200):</strong> </p>
  
  <pre><code>public IEnumerable&lt;MyObject&gt; Get(int id, string format)
  {
      var db = new DbEntities();
  
      var result = db.pr_ApiSelectMyObjectType(store, id, format);
      if (result == null)
      {
          var response = new HttpResponseMessage(HttpStatusCode.NoContent) 
              { Content = new StringContent("Unable to find any results") };
          throw new HttpResponseException(response);
      }
      return result.AsEnumerable();
  }
  </code></pre>
  
  <p>How do I pass back a 404 if no results are found?  I know I could use a list, but I have a custom csv media type formatter that only works with IEnumerable types, so I would prefer to stick with that.  </p>