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: 
I was having the same question If ListIterator is interface which contains only abstract method which class is responsible for the implementation those methods.

arrived on the conclusion (correct me if I'm wrong)

ArrayList instance method ListIterator is returning instance of ListItr(0)
ListItr(java.util.ArrayList.ListItr) is the class which is implementing the ListIterator interface with the implementation of the abstract methods.
Technically ListIterator can hold instance of it's implementation class.
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).