Quantcast
Channel: patterns & practices: Project Silk
Viewing all articles
Browse latest Browse all 93

New Post: IQueryable in IEnumerable

$
0
0
Hi

In the documentation of Project silk it says following:

"In Mileage Stats, the implementation of the iReminderRepository calls Tolist before returning the iEnumerable<T>. This is to ensure that the query is executed inside the repository. If Tolist was not called, then the repository would return an iQueryable<T> and the database would not be accessed until something iterated over the iQueryable<T> object."

A code expample:
 public IEnumerable<Reminder> GetRemindersForVehicle(int vehicleId)
        {
            return this.GetDbSet<Reminder>()
                .Where(v => v.VehicleId == vehicleId)
                .ToList();
        }
Does that mean that even though the result is returned like IEnumerable, this would just be a container for a IQueryable, and if ToList() would not be called than one could be making calls on the IEnumerable as if it was a IQueryable?

Is this really right? It sounds wrong to me. If you where to make calls on the IEnumerable<Reminder>, that is returned if ToList isn't called, it would be the extension methods of IEnumerable that would be used and not IQueryable.

How can they clame that the function is returning a iQueryable<T> if ToList is not called, how is that possible?

It would be right if the method was returning a iQueryable<T> but it dosen't.

Viewing all articles
Browse latest Browse all 93

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>