
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What is the difference between IEnumerable and IQueryable in C#?
- IEnumerable exists in System.Collections Namespace.
- IQueryable exists in System. Linq Namespace.
- Both IEnumerable and IQueryable are forward collection.
- IEnumerable doesn’t support lazy loading
- IQueryable support lazy loading
- Querying data from a database, IEnumerable execute a select query on the server side, load data in-memory on a client-side and then filter data.
- Querying data from a database, IQueryable execute the select query on the server side with all filters.
- IEnumerable Extension methods take functional objects.
- IQueryable Extension methods take expression objects means expression tree.
Example
IEnumerable
dbContext dc = new dbContext (); IEnumerable <SocialMedia> list = dc.SocialMedias.Where(p => p.Name.StartsWith("T")); list = list.Take<SocialMedia>(1); </SocialMedia>
Sql statement generated for the above query
SELECT [t0].[ID], [t0].[Name] FROM [SocialMedia] AS [t0] WHERE [t0].[Name] LIKE @p0
IQueryable
dbContext dc = new dbContext (); IQueryable<SocialMedia> list = dc.SocialMedias.Where(p => p.Name.StartsWith("T")); list = list.Take<SocialMedia>(1);
Sql statement generated for the above query
SELECT top 1 [t0].[ID], [t0].[Name] FROM [SocialMedia] AS [t0] WHERE [t0].[Name] LIKE @p0
- Related Articles
- Difference between IEnumerator and IEnumerable Interface in C#
- What does the interface IEnumerable do in C#?
- How to convert IEnumerable to List and List back to IEnumerable in C#?
- What is the difference Between C and C++?
- What is the difference between | and || operators in c#?
- What is the difference between JavaScript and C++?
- What is the difference between ++i and i++ in c?
- What is the difference between literal and constant in C++?
- What is the difference between ++i and i++ in C++?
- What is the difference between overriding and shadowing in C#?
- What is the difference between String and string in C#?
- What is the difference between literal and constant in C#?
- What is the difference between declaration and definition in C#?
- What is the difference between objects and classes in C#?
- What is the difference between overriding and hiding in C#?

Advertisements