Showing posts with label IQueriable. Show all posts
Showing posts with label IQueriable. Show all posts

Monday, June 3, 2013

IEnumerable Vs IQueryable

IQueryable

The
IQueryable interface allows the objects to be queried based on the LINQ-to-SQL. Objects which implement the IQuerieable interface can be further queried using LINQ queries and these additional queries will be executed on the underlying data source.

The below line first queries the list of employees from the datasource, the resultant object empList is further queried based on the department name of the employee, both the filters are done in the underlying datasource and only the final list of employees belonging to the sales department are returned and stored in the memory, using LINQ-to-Sql. Hence more efficient based on
IEnumerable based objects.

IQueriable Interface

The IQueriable interface is used to execute queries against a data source, where the type of ata returned from the source is not known at design time.

IQueriable interface inherits from the IEnemurable interface, and allows the objects to be queried based on the underlying data source, hence they are more efficient when the types are to be queried/filtered further.

Namespace:  System.Linq