Part 17 AsEnumerable and AsQueryable in LINQ

preview_player
Показать описание
Text version of the video

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

Slides

LINQ Tutorial - All Text Articles & Slides

LINQ Tutorial Playlist

Dot Net, SQL, Angular, JavaScript, jQuery and Bootstrap complete courses

In this video we will discuss the use of AsEnumerable and AsQueryable operators in LINQ. Both of these operators belong to Conversion Operators category.

AsQueryable operator : There are 2 overloaded versions of this method.
One overloaded version converts System.Collections.IEnumerable to System.Linq.IQueryable
The other overloaded version converts a generic System.Collections.Generic.IEnumerable[T] to a generic System.Linq.IQueryable[T]

The main use of AsQueryable operator is unit testing to mock a queryable data source using an in-memory data source. We will discuss this operator in detail with examples in unit testing video series.

AsEnumerable operator breaks the query into 2 parts
1. The "inside part" that is the query before AsEnumerable operator is executed as Linq-to-SQL
2. The "ouside part" that is the query after AsEnumerable operator is executed as Linq-to-Objects

So in this example the following SQL Query is executed against SQL Server, all the data is brought into the console application and then the WHERE, ORDERBY & TOP operators are applied on the client-side
SELECT [t0].[ID], [t0].[Name], [t0].[Gender], [t0].[Salary]
FROM [dbo].[Employees] AS [t0]

So in short, use AsEnumerable operator to move query processing to the client side.
Рекомендации по теме
Комментарии
Автор

Mr.Venkat I would like to thank you from the bottom of my heart.Your mvc tutorials were the starting point of my mvc career.I have been working with a company using MVC 5 for some time now.Thanks again god bless you.

FH
Автор

These videos are gold, kudvenkat you help sooo many aspiring programmers all around the world

Nabolzi
Автор

Again everything is explained with simplicity. Thank you Venkat...

shalabhsaxena
Автор

what is the benefits when I executed query on the memory rather than on the database side?

User_Masuri
Автор

You do things uniquely and explain them precisely... Thanks for knowledge sharing !!

komalkushwaha
Автор

Hi Venkat! Your tutorials make me better programmer.

kamdemkakengne
Автор

Please explain Asqueryable().And also in what case we have to use AsEnumerable and Asqueryable

greeshmanair
Автор

kudvenkat Can you please explain a case when AsEnumerable would be required?

shyamal
Автор

Very nicely explained, good video. But where is AsQueryable ?
I think sir you must be interactive also... You have not replied to anyone's comment...

manpreetall
Автор

shall we use edmx instead of dbml sir?

Ak
Автор

Explanation was simple and understood very well. but one query comes to mind why we need to do so. Where can we apply this concept in real world projects?

computer_programming_gk
Автор

What is the use of moving query processing to client side?

PraveenKumar-vdvd
Автор

Can somebody tell why one will use AsEnumerable? Asking because its never a good idea to get a huge collection in memory and then operate on it.

aman
Автор

Nice. Thanks for the tutorial . I've one quest. Which operator it default takes? as if we do not use any operator then result come direct from SQL Server collection like IQueryable.

swapnilmehta
Автор

video is full of knowledge but AsQueryable is not discussed

vib
Автор

For all of those who wants to understand the difference with AsQueryable, read here

Beacher
Автор

excellent video. But when where do we discussed AsQuearyable?

pardhasaradhi
Автор

Good  vid but AsQueryable is not discussed in the video

JediBackSlash
Автор

AsQueryble is not discussed. Anyway nice explanation

amolwani
Автор

can you explain repository framework please ?

anishtaneja