What is the difference between IQueryable
and IEnumerable
?
See also What\'s the difference between IQueryable and I
In real life, if you are using a ORM like LINQ-to-SQL
In both cases if you don't call a ToList()
or ToArray()
then query will be executed each time it is used, so, say, you have an IQueryable
and you fill 4 list boxes from it, then the query will be run against the database 4 times.
Also if you extent your query:
q.Where(x.name = "a").ToList()
Then with a IQueryable the generated SQL will contains “where name = “a”, but with a IEnumerable many more roles will be pulled back from the database, then the x.name = “a” check will be done by .NET.