hi,
What is IEnumerable & IQueryable type object in Linq ? Please Explain it.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
MuthuMari MPosted Apr 24, 2012, 8:38 AM
pls refer this url
http://stackoverflow.com/questions/252785/what-is-the-difference-between-iqueryablet-and-ienumerablet/252857#252857
thanks.
If this post is useful then mark it as "Accepted Answer"
Shenishetty SravaniPosted Apr 24, 2012, 8:09 AM
Using IQueryable
It is used for filtering the records in extension methods.
When we use:
public static IQueryable
{
return Employees.Where(e => e.Salary >= 10000);
}
When the method is executed,the SQL executed will be "Select * from Employee where Salary>=10000".
It returns only those records in to the collection which satisfy the condition.
but when we use IEnumerable ,the SQL executed will be "Select * from Employee" and returns every record.
IQueryable extends IEnumerable, and also stores the Expressions (not just Funcs). Whereas a Func is a delegate and an Expression is, well, an expression that is able to be traversed at runtime. And that means it can be translated into SQL.
The .Where extension method for an IEnumerable takes a Func
What this means is that if we change our filter extension method to take an IEnumerable, it will be using the IEnumerable's .Where extension method, passing in a compiled delegate instead of a traversable expression (they both can be inferred from the same code, in the above case e => e.Salary >= 10000, how it gets compiled depends on which method you call).
For more information on Linq follow the link below:new link
VulpesPosted Apr 23, 2012, 12:57 PM
Local queries operate over collections which implement IEnumerable
Interpreted queries operate over collections which implement IQueryable
It is also possible to query non-generic collections which implement IEnumerable (for local queries) or IQueryable (for interpreted queries) by casting to a specific type.