I'm confused as to the difference. Being fairly new to .Net, I know I can query IEnumerables
using the Linq extensions. So what is this IQueryable
and how does it differ?
See also What is the difference between IQueryable[T] and IEnumerable[T]? that overlaps with this question.
In real life, if you are using a ORM like LINQ-to-SQL
IQueryable
, then the query may be converted to sql and run on the database serverIEnumerable
, then all rows will be pulled into memory as objects before running the query.In both cases if you don't call a
ToList()
orToArray()
then query will be executed each time it is used, so, say, you have anIQueryable
and you fill 4 list boxes from it, then the query will be run against the database 4 times.Also if you extend your query:
Then with an
IQueryable
the generated SQL will containwhere name = "a"
, but with anIEnumerable
many more roles will be pulled back from the database, then thex.name = "a"
check will be done by .NET.