Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Sunday, 21 May 2017

Difference Between IEnumerable And IQueryable In C# With Example

 Difference between ienumerable and iqueryable, Ienumerable in c#, Ienumerable vs Iqeryable, IQueryable in c#     No comments   


Introduction
In this article we will learn what is the difference between IEnumerable and IQueryable in c#. What is IEnumerable  and IQueryable. When to use IQueryable  and when to use IEnumerable  in c#. What is the use of Ienumerable and IQueryable in C# also IEnumerable  and IQueryable difference in C#.

Previous Updates
In previous articles we have learnt AngularJS basics,  Ransomware attack and Precautions, Difference between Row_Number(), Rank(), Rank_Density() with example.
Const Readonly and Static difference in C#,  Best basic C# interview questions.

Why do we need IEnumerable and IQueryable
Both IEnumerable and IQueryable are used for to hold the collection of a data and performing data manipulation operation for example filtering on the collection of data.

IEnumerable 
1. BY using System.Collection namespace we can add access or use the IEnumerable in our code.
2. IEnumerable is much slower in processing because when selecting data from database it  executes select query on server side, load data in-memory on client side and then filter data. 

For Example you have a Employee table with lacks of records and you need to select all the records which having salary less then 10,000. Selecting records using IEnumerable then it select all the records from the table and load all of them into memory after that it will perform filtration and will searched for Employee less then 10,000 salary.


DataClasses1DataContext dbcon = new DataClasses1DataContext();
       IEnumerable<EmployeeDetail> emplist = dbcon.EmployeeDetails.Where
                                              (e => e.Salary < 10000 );

3. IEnumerable is only preferable for small data manipulations.
4. Best use of IEnumerable is with LINQ to Objects and LINQ to XML operations.Because it load all the data in memory the performs any operation.

IQueryable
1. BY using System.Linq namespace we can add access or use the IQueryable in our code.
2. IQueryable  is much faster in processing because it do not load all the data in memory. 

For Example you have a Employee table with lacks of records and you need to select all the records which having salary less then 10,000. Performing SELECT query on table using IQueryable then it select only filtered record from the table(Gets only Salary <10000 Employess). It will not load all the records into memory. That's why it is fast.


DataClasses1DataContext dbcon = new DataClasses1DataContext();
       IEnumerable<EmployeeDetail> emplist = dbcon.EmployeeDetails.Where
                                              (e => e.Salary < 10000 );


3. By using IQueryable you can perform big data manipulation tasks.
4. IQueryable is used in LINQ To SQL Queries.






IEnumerable
IQueryable
Namespace used
System.Collections
System.Linq
Derived Interface
No base interface
Derives from IEnumerable
Lazy Loading
Not Supported.
Supported
Best Suitable For
LINQ to Object and LINQ to XML queries.
LINQ to SQL queries.
Custom Query
Doesn’t supports.
Supports using CreateQuery and Execute methods.
When To Use
Working with the read only collection.
Need to read the objects in forward direction only.
Not concerned about thread safety.
Want to iterate the collection’s objects using foreach.
Working with the queryable datasource.
Need to apply filter on data at the datasource.
Need to apply paging , composition.
Working with external data source.
Needs to load data in deferred way.
Need to use foreach to iterate collection.

  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Categories

Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS Scope_Identity() Use of indexes comma seperated string in sql row_number() and dense_rank() salary table structure. while loop in sql why do we need cursor why tuple used

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write