title: Entity Framework query with ToList().Last() in Where()
body: <p>I have to get records from database which last of <code>OrderStatus</code> is <code>Registered</code>. This is how I try to find those records</p>
  
  <pre><code>    List&lt;Order&gt; orders = db.Orders
          .Include("OrderStatuses")
          .Where(x =&gt; x.OrderStatuses.ToList().Last().Status == StatusOrder.Registered)
          .ToList();
  </code></pre>
  
  <p>but I get exception </p>
  
  <blockquote>
    <p>LINQ to Entities does not recognize the method
    'Lomax.Models.OrderStatus
    LastOrderStatus'
    method, and this method cannot be translated into a store expression.</p>
  </blockquote>
  
  <p>Is there any way not getting all <code>Orders</code> from db first and then looking for those which last <code>OrderStatus</code> is which I want? Or it doesn't matter (in speed)?</p>
  
  <p>Order class:</p>
  
  <pre><code>public class Order
      {
          [Key]
          public int ID { get; set; } 
          (...)
          public virtual ICollection&lt;OrderStatus&gt; OrderStatuses { get; set; }
      }
  </code></pre>
  
  <p>OrderStatus class:</p>
  
  <pre><code>public class OrderStatus
      {
          [Key]
          public int ID { get; set; }
          public DateTime Date { get; set; }
          public Enumerates.StatusOrder Status { get; set; }
  
          [ForeignKey("Order")]
          public int OrderID { get; set; }
          public virtual Order Order { get; set; }
      }
  </code></pre>