Advertisement
Filkolev

Play With To List

Jul 23rd, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. public static void Main()
  2.         {
  3.             const string CleanBuffersSqlQuery = "CHECKPOINT; DBCC DROPCLEANBUFFERS;";
  4.             const int NumberOfIterations = 10;
  5.             Stopwatch stopwatch = new Stopwatch();
  6.  
  7.             for (int i = 0; i < NumberOfIterations; i++)
  8.             {
  9.                 using (var context = new AdsEntities())
  10.                 {
  11.                     context.Database.SqlQuery<string>(CleanBuffersSqlQuery);
  12.  
  13.                     stopwatch.Start();
  14.                     var ads =
  15.                         context.Ads.ToList()
  16.                             .Where(a => a.AdStatus.Status == "Published")
  17.                             .Select(a => new { a.Title, a.Category, a.Town, a.Date })
  18.                             .ToList()
  19.                             .OrderBy(a => a.Date);
  20.                     stopwatch.Stop();
  21.                     Console.WriteLine("Iteration {0}: {1}", i + 1, stopwatch.Elapsed);
  22.                 }
  23.  
  24.                 stopwatch.Reset();
  25.             }
  26.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement