While query data from database, IQueryable execute select query on server side with all filters (e.g SQL select statement on database server). IEnumerable filters the data on client side. (in memory in application)
IEnumerable Example
- MyDataContext dc = new MyDataContext ();
- IEnumerable<Employee> list = dc.Employees.Where(p => p.Name.StartsWith(“S”));
- list = list.Take<Employee>(10);
Generated SQL statements of above query will be :
- SELECT [t0].[EmpID], [t0].[EmpName], [t0].[Salary] FROM [Employee] AS [t0]
- WHERE [t0].[EmpName] LIKE @p0
Notice that in this query “top 10” is missing since IEnumerable filters records on client side
IQueryable Example
- MyDataContext dc = new MyDataContext ();
- IQueryable<Employee> list = dc.Employees.Where(p => p.Name.StartsWith(“S”));
- list = list.Take<Employee>(10);
Generated SQL statements of above query will be :
- SELECT TOP 10 [t0].[EmpID], [t0].[EmpName], [t0].[Salary] FROM [Employee] AS [t0]
- WHERE [t0].[EmpName] LIKE @p0
Notice that in this query “top 10” is exist since IQueryable executes query in SQL server with all filters.
Source: IEnumerable VS IQueryable