For example, if we have two tables Country and cities then you'll write code like:
Now, Imagine there are 100 Countries and each Country has at least 100 Cities, then at least 10000 queries will be executed. Lot of performance effect.
Fortunately there is a way to avoid this problem. Using Include(…) method only one query is made to the Database. No Extra queries will be made to the database Now your code will be:
Please do like/Comment/share if you like this.
- foreach (var country in countriesEntities.Countries)
- {
- Console.WriteLine(country.CountryName + "\nCities:");
- foreach (var city in country.Cities)
- {
- Console.WriteLine("{0}", city.CityName);
- }
- }
Now, Imagine there are 100 Countries and each Country has at least 100 Cities, then at least 10000 queries will be executed. Lot of performance effect.
Fortunately there is a way to avoid this problem. Using Include(…) method only one query is made to the Database. No Extra queries will be made to the database Now your code will be:
- foreach (var country in countriesEntities.Countries.Include("Cities"))
- {
- Console.WriteLine(country.CountryName + "\nCities:");
- foreach (var city in country.Cities)
- {
- Console.WriteLine(" {0}", city.CityName);
- }
- }
Please do like/Comment/share if you like this.
Hey its look gud to me !! Choudhary Bhai
ReplyDeleteThanks Rakesh :)
ReplyDeleteNice!
ReplyDelete