AsQueryable doesn't really do anything when invoked on a plain old collection like a List<T>
, so the answer probably depends on another part of the codebase. For example, someone might have defined a GetBooks method to take an IQueryable<Book>
, with the intent that the GetBooks method would perform any ordering or filtering in the database via a LINQ provider. But the code you're looking at constructs the set of books as a collection (a List<Book>
), not a query. In order for the result to be passed the hypothetical GetBooks method, the collection has to be wrapped in an IQueryable<Book>
, even though that wrapper is just going to delegate straight back to the LINQ to Objects methods (rather than translating the GetBooks operations to SQL queries).
Or perhaps the class you're looking at implements an interface where the method you're looking at is declared as returning IQueryable<Book>
(for similar reasons to above), so your code is having to wrap the List<Book>
to remain compatible with the interface signature.