Part 8 Lazy loading in LINQ to SQL04:33

  • 0
Published on May 30, 2017

Link for all dot net and sql server video tutorial playlists

Link for slides, code samples and text version of the video

In this video we will discuss the concept of Lazy loading in LINQ to SQL with an example.

In this example there is a One-to-Many relationship between Department and Employee entities. A Department can have 1 or more employees. When Departments are loaded the related entities (Employee entities) are not loaded. Employee entities are only loaded when we iterate thru the employee objects belonging to a given department.

To prove this, uncomment the following line and run the console application again. Notice that there is one query to retrieve all the departments and 3 queries to retrieve the employees belonging to each department.
//dbContext.Log = Console.Out;

So, what is Lazy Loading
Lazy Loading means the related entities are not loaded until we iterate thru them or data bind them. By default, LINQ to SQL loads related entities by using Lazy Loading.

In our next video, we will discuss how to change this behavior and eager load the related entities.

https://cafeadobro.ro/

https://www.stagebox.uk/wp-includes/depo10-bonus10/

https://iavec.com.br/

Enjoyed this video?
"No Thanks. Please Close This Box!"