Venciity

Untitled

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