What are the differences between IEnumerable and IQueryable?

Technology CommunityCategory: C#What are the differences between IEnumerable and IQueryable?
VietMX Staff asked 3 years ago
  • The IEnumerable<> interface indicates that something can be enumerated across–in other words, you can do a foreach loop on it.
  • The IQueryable<> interface indicates that something has some kind of backing query provider that’s capable of looking at Expressions that are given to it, and translate them into some kind of query.

What IQueryable has that IEnumerable doesn’t are two properties in particular—one that points to a query provider (e.g., a LINQ to SQL provider) and another one pointing to a query expression representing the IQueryable object as a runtime-traversable abstract syntax tree that can be understood by the given query provider (for the most part, you can’t give a LINQ to SQL expression to a LINQ to Entities provider without an exception being thrown).