title: How to cast my Linq query to the expected Web API return type
body: <p>My .Net Core Web API call is not returning values to the browser, but hanging the browser.</p>
  
  <p>I have these models:</p>
  
  <pre><code>public class Status
      {
      public long StatusId { get; set; }
      public long UserId { get; set; }
      public string Body { get; set; }
      public virtual User User { get; set; }
      }
  
  public class User
      {
      public long UserId { get; set; }
      public string Name { get; set; }
      public string Email { get; set; }
      public virtual ICollection&lt;Status&gt; Statuses { get; set; }
      }
  </code></pre>
  
  <p>My Status controller's Get functions look like this:</p>
  
  <pre><code>[HttpGet]
  public IEnumerable&lt;Status&gt; GetAll()
      {
      var rv =  _context.Statuses.ToList();
      return rv;
      }
  </code></pre>
  
  <p>When I GET the API endpoint, I get the first record, then the browser hangs (keeps loading) and the rest of the data never comes through.</p>
  
  <p>Stepping into my code, I see that rv is getting populated with all of the records, but we have the problem of the <code>User</code> having <code>Statuses</code> and then the <code>Statuses</code> have a <code>User</code> and so on - circular reference.</p>
  
  <p>Ok, so let's try this in the controller so we don't get the <code>Statuses</code> from <code>User</code>:</p>
  
  <pre><code>var rv = _context.Statuses.Select(s =&gt; new
      {
      StatusId = s.StatusId,
      UserId = s.UserId,
      Body = s.Body,
      User = from u in _context.Users
             select new
                 {
                 UserId = u.UserId,
                 Name = u.Name,
                 Email = u.Email,
                 }
      }
  
      ).ToList();
  
  return rv;
  </code></pre>
  
  <p>Problem is <code>rv</code> is an anonymous type and I can't figure out how to successfully type it to the <code>IEnumerable&lt;Status&gt;</code> return type, even though it is the same as the model (excepting the missing <code>Statuses</code> in the <code>User</code>). Or do I change the return type and what to?</p>