Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- / Problem 1. Show Data from Related Tables
- Console.WriteLine("List ads (with N+1 query problem):");
- var ads = new List<string>();
- var startTime = DateTime.Now;
- var context = new AdsEntities();
- foreach (var ad in context.Ads)
- {
- ads.Add(string.Format("Title: {0}, Status: {1}, Category: {2}, Town: {3}, User: {4}",
- ad.Title, ad.AdStatus.Status, ad.Category, ad.TownId, ad.AspNetUser.UserName));
- }
- Console.WriteLine("Time elapsed: {0}", DateTime.Now - startTime);
- Console.WriteLine(String.Join("\n", ads.Take(5)));
- Console.WriteLine("...");
- Console.WriteLine();
Advertisement
Add Comment
Please, Sign In to add comment