Question: On this Function I get an Invalid Cast Exception with this as the Detailed error

> 
> Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery`1[<>f__AnonymousType8`2[System.Nullable`1[System.TimeSpan],System.String]]' to type 'System.Linq.IOrderedQueryable`1[YourReservation.Models.Reservation]'.
> 
> 
> 

Code:

```
[HttpGet]
[Route("api/Reservations/getPartyNames")]
public IOrderedQueryable<Reservation>getPartyNames()
{
    var query = (from r in db.Reservations
                 where r.ReservationDate == DateTime.Now
                 select new { Time = r.ReservationTime, FullName = r.FirstName + " " + r.LastName });

    return (IOrderedQueryable<Reservation>)query;
}

```

I don't exactly see what is wrong because I have made this particular cast on a return variable numerous times before.

Answer: 
An iterator over a collection. Iterator takes the place of Enumeration in the Java Collections Framework. Iterators differ from enumerations in two ways:
Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics.
Method names have been improved.

<https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html>
The `next()` and `hasNext()` methods are part of the `Iterator` interface. Each specific implementation will provide their own versions. You can take a look at how they are defined for the `ArrayListIterator` in the commons-collection library [here](http://grepcode.com/file_/repo1.maven.org/maven2/commons-collections/commons-collections/3.2.1/org/apache/commons/collections/iterators/ArrayListIterator.java/?v=source) or `SingletonListIterator` [here](http://grepcode.com/file_/repo1.maven.org/maven2/commons-collections/commons-collections/3.2.1/org/apache/commons/collections/iterators/SingletonListIterator.java/?v=source).