示例#1
0
        static void Main(string[] args)
        {
            using (var context = new AdsEntities())
            {
                /* The slow version */
                var adsWithoutInclude = context.Ads;

                foreach (var ad in adsWithoutInclude)
                {
                    Console.WriteLine("{0}; {1}; {2}; {3}; {4}",
                        ad.Title,
                        (ad.AdStatus != null ? ad.AdStatus.Status : "null"),
                        (ad.Category != null ? ad.Category.Name : "null"),
                        (ad.Town != null ? ad.Town.Name : "null"),
                        (ad.AspNetUser != null ? ad.AspNetUser.UserName : "******"));
                }

                /* The fast version */
                var adsWithInclude = from ad in context.Ads.Include(a => a.AdStatus)
                                                .Include(a => a.Category)
                                                .Include(a => a.Town)
                                                .Include(a => a.AspNetUser)
                                     select ad;

                foreach (var ad in adsWithInclude)
                {
                    Console.WriteLine("{0}; {1}; {2}; {3}; {4}",
                        ad.Title,
                        (ad.AdStatus != null ? ad.AdStatus.Status : "null"),
                        (ad.Category != null ? ad.Category.Name : "null"),
                        (ad.Town != null ? ad.Town.Name : "null"),
                        (ad.AspNetUser != null ? ad.AspNetUser.UserName : "******"));
                }
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            using (var context = new AdsEntities())
            {
                /* The slow version */
                var adsSlow = context.Ads
                    .ToList()
                    .Where(a => a.AdStatus != null && a.AdStatus.Status == "Published")
                    .Select(a => new
                    {
                        Title = a.Title,
                        PublishDate = a.Date,
                        Category = a.Category,
                        Town = a.Town
                    }).ToList()
                    .OrderBy(a => a.PublishDate);

                /* The fast version */
                var adsFast = from ad in context.Ads
                    where ad.AdStatus.Status == "Published"
                    orderby ad.Date
                    select new
                    {
                        Title = ad.Title,
                        Category = ad.Category,
                        Town = ad.Town
                    };
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            using (var context = new AdsEntities())
            {
                /* The slow version */

                var ads = from ad in context.Ads
                    select ad;

                /* The fast version */

                var adsTitles = from ad in context.Ads
                    select ad.Title;
            }
        }