IEnumerable Vrs IQueryable

 Posted by Sumank on 5/14/2013 | Category: LINQ Interview questions | Views: 3099 | Points: 40
Answer:

IEnumerable Vrs IQueryable


In Linq, to query data from database and collections we use IEnumerable and IQueryable. IEnumerable is inherited by IQueryable, so it has all features of it and of its capabilities. Both has their own importance to query data and data manipulation.


IEnumerable :-

1. It exists in System.Collection namespace.
2. It can move forward only over collection.
3. It is best to query data from in-memory collections like Array, List, etc.
4. It is suitable for Linq to Objects and Linq To Xml queries.
5. It doesn't support lazy loading, hence not suitable for paging like scenario.

DataContextClasses db= new DataContextClasses();
IEnumerable<Employee>List =dc.Employees.Where(m=>m.Name.StartsWith("a"));
list=list.Take<Employee>(10);


IQueryable :-

1. It exists in System.Linq namespace.
2. It can move forward only over collection.
3. It is best to query data from out-memory like remote database.
4. It is suitable for Linq to Sql queries.
5. It support lazy loading, hence suitable for paging like scenario.

DataContextClasses db= new DataContextClasses();
IQueryable<Employee>List =dc.Employees.Where(m=>m.Name.StartsWith("a"));
list=list.Take<Employee>(10);


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response