private static void NonOptimised(AdsEntities context)
 {
     var titles = context.Ads;
     foreach (var title in titles)
     {
         Console.WriteLine("Non-optimized: {0}", title.Title);
     }
 }
        private static void Optimized(AdsEntities context)
        {
            var titlesOpt = context.Ads
                .Select(t => new
                {
                    t.Title
                });

            foreach (var title in titlesOpt)
            {
                Console.WriteLine("Optimized: {0}",
                    title.Title);
            }
        }
 private static void OptimizedList(AdsEntities context)
 {
     var adsOpt = context.Ads
         .Where(a => a.AdStatus.Status.Equals("Published"))
         .OrderBy(a => a.Date)
         .Include(a => a.Category)
         .Include(a => a.Town).ToList();
     adsOpt.ForEach(a =>
     {
         Console.WriteLine("{0} {1} {2}",
             a.Title,
             (a.CategoryId != null) ? a.Category.Name : "no category",
             (a.TownId != null) ? a.Town.Name : "no town");
     });
 }
        static void Main()
        {
            var context = new AdsEntities();
            context.Ads.Count();

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            UnoptimizedToList(context);
            //Console.WriteLine(stopWatch.Elapsed);

            stopWatch.Restart();
            OptimizedList(context);
            Console.WriteLine(stopWatch.Elapsed);
        }
 private static void UnoptimizedToList(AdsEntities context)
 {
     var ads = context.Ads
         .ToList()
         .Where(a => a.AdStatus.Status == "Published")
         .OrderBy(a => a.Date)
         .Select(a => new
         {
             a.Title,
             CategoryName= a.CategoryId != null ? a.Category.Name : "no category",
             TownName =(a.TownId != null) ? a.Town.Name : "no town"
         }).ToList();
     foreach (var ad in ads)
     {
         Console.WriteLine("{0} {1} {2}",
             ad.Title,
             ad.CategoryName,
             ad.TownName);
     }
 }