Part 17 AsEnumerable and AsQueryable in LINQ
kudvenkat kudvenkat
825K subscribers
113,663 views
0

 Published On Jul 24, 2014

Text version of the video
http://csharp-video-tutorials.blogspo...

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.
   / @aarvikitchen5572  

Slides
http://csharp-video-tutorials.blogspo...

LINQ Tutorial - All Text Articles & Slides
http://csharp-video-tutorials.blogspo...

LINQ Tutorial Playlist
   • LINQ Tutorial  

Dot Net, SQL, Angular, JavaScript, jQuery and Bootstrap complete courses
https://www.youtube.com/user/kudvenka...

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.

show more

Share/Embed