find and solve || findandsolve.com
Please wait.....

Welcome back.






Before Read Terms of use

IEnumerable vs IQueryable

IQueryable and IEnumerable is main different between filter logic from execute from database. One executes on the client side (in memory) and the other executes on the database.IQueryable and IEnumerable are interfaces that allows  manipulate and query collections of data. IEnumerable is inherited by IQueryable.IQueryable add features to IEnumerable interface.


IEnumerable:

IEnumerable is  first load all data in memory then apply the filter for different types of parameters.Execute query on server side, load data in-memory on client side and then filter data.For example, I have 50000 employee record in database.I want to get 3000 data record where employee salary is grater then 50,000,so in this case if use IEnumberable approach then first it load all employee 5000 records in the memory then apply the grater then 50,000 filter  on it which eventually returns the 3000 records.This is tow steps process and load all the record in memory as well which will make the process slow.
//IEnumerable :Not recommended approach

IEnumerable<Employee> Employees = ...;
var employeeList = Employees.Where(x => x.Salary >=30000);

IEnumerable Is:

System.Collections namespace
LINQ to Object and LINQ to XML
NO lazy loading
in-memory queries
doesn’t support custom query
Extension methods support by IEnumerable takes functional objects
IEnumerable can move forward only over a collection

IQueryable:

IQueryable execute select query from server side with all filters.IQueryable allows for out-of-memory things like a remote data source, such as a database or web service.IQueryable interface inherits from IEnumerable,IEnumerable can do, IQueryable can also do.
//IQueryable:recommended approach

IQueryable<Employee> Employees = ...;
var employeeList = Employees.Where(x => x.Salary >=30000);

IQueryable Is

System.Linq namespace
LINQ to SQL
Lazy loading
Out-memory (serverside) queries
Supports custom query
IQueryable can move forward only over a collection
IQueryable supports deferred execution.
Extension methods support by IQueryable takes expression objects means expression tree

Sundar  Neupane

Sundar Neupane

I like working on projects with a team that cares about creating beautiful and usable interfaces.

Comments



Report Response