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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Apr 23, 2012, 8:57 AM EDT
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.
Shenishetty Sravani2 reputationPosted Apr 24, 2012, 4:09 AM EDT
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
MuthuMari MRank #5,738 · 288 reputationPosted Apr 24, 2012, 4:38 AM EDT
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"