コード例 #1
0
 private static void AdsWithoutInclude(AdsEntities db)
 {
     foreach (var ad in db.Ads)
     {
         Console.WriteLine("{0} {1} {2} {3} {4}",
             ad.Title,
             ad.AdStatus.Status,
             (ad.CategoryId == null) ? "no data" : ad.Category.Name,
             (ad.TownId == null) ? "no town" : ad.Town.Name,
             ad.AspNetUser.Name);
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: Bare7a/Software-University
        static void Main()
        {
            var db = new AdsEntities();
            var stopWatch = new Stopwatch();
            stopWatch.Start();
            SlowQuery(db);
            Console.WriteLine("Slow query: " + stopWatch.Elapsed);

            stopWatch.Restart();

            OptimizedQuery(db);
            Console.WriteLine("Optimized query: " + stopWatch.Elapsed);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Bare7a/Software-University
 private static void SlowQuery(AdsEntities db)
 {
     var ads = db.Ads
         .ToList()
         .Where(a => a.AdStatus.Status == "Published")
         .OrderBy(a => a.Date)
         .SelectMany(a => new[]
         {
             a.Title,
             (a.CategoryId == null) ? "no category" : a.Category.Name,
             (a.TownId == null) ? "no town" : a.Town.Name,
         }).ToList();
     //for (int i = 0; i < ads.Count; i += 3)
     //{
     //    Console.WriteLine("{0} {1} {2}", ads[i], ads[i + 1], ads[i + 2]);
     //}
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: Bare7a/Software-University
        private static void OptimizedQuery(AdsEntities db)
        {
            var ads = db.Ads
                .Where(a => a.AdStatus.Status == "Published")
                .OrderBy(a => a.Date)
                .Include(a => a.Category)
                .Include(a => a.Town)
                .ToList();

            //foreach (var ad in ads)
            //{
            //    Console.WriteLine("{0} {1} {2}",
            //        ad.Date,
            //        (ad.CategoryId == null) ? "no category" : ad.Category.Name,
            //        (ad.TownId == null) ? "no town" : ad.Town.Name);
            //}
        }
コード例 #5
0
        static void Main()
        {
            var db = new AdsEntities();

            var stopWatch = new Stopwatch();
            stopWatch.Start();
            var selectAllFromAds = db.Ads;
            foreach (var selectAllFromAd in selectAllFromAds.Take(3))
            {
                Console.WriteLine(selectAllFromAd.Title);
            }
            Console.WriteLine("Select all from ads: " + stopWatch.Elapsed);

            stopWatch.Restart();

            var selectTitleFromAds = db.Ads.Select(a => a.Title);
            foreach (var selectTitleFromAd in selectTitleFromAds.Take(3))
            {
                Console.WriteLine(selectTitleFromAd);
            }

            Console.WriteLine("Select title from ads: " + stopWatch.Elapsed);
        }
コード例 #6
0
        static void Main()
        {
            var db = new AdsEntities();

            AdsWithoutInclude(db);
        }
コード例 #7
0
 public static void Main()
 {
     var db = new AdsEntities();
     var adsCount = db.Ads.Count();
 }