예제 #1
0
 private static void PrintWithoutInclude(TelerikAcademyEntities db)
 {
     foreach (var emp in db.Employees)
     {
         Console.WriteLine("DepartmentID: {0}, {1} {2}\tFrom {3}",
             emp.Department.DepartmentID,
             emp.FirstName,
             emp.LastName,
             emp.Address.Town.Name);
     }
 }
예제 #2
0
        static void Main(string[] args)
        {
            TelerikAcademyEntities db = new TelerikAcademyEntities();
            string firstResult, secondResult;
            Stopwatch sw = new Stopwatch();
            sw.Start();

            PrintWithoutInclude(db);

            sw.Stop();
            firstResult = sw.Elapsed.ToString();

            sw.Restart();
            PrintWithInclude(db);
            sw.Stop();
            secondResult = sw.Elapsed.ToString();

            Console.WriteLine("Time without include: {0}", firstResult);
            Console.WriteLine("Time with include: {0}", secondResult);
        }
예제 #3
0
        static void Main(string[] args)
        {
            TelerikAcademyEntities db = new TelerikAcademyEntities();
            string firstResult, secondResult;
            Stopwatch sw = new Stopwatch();
            sw.Start();

            var towns = db.Employees.ToList()
                .Select(emp => emp.Address).ToList()
                .Select(town => town.Town).ToList()
                .Where(town => town.Name == "Sofia");

            sw.Stop();
            firstResult = sw.Elapsed.ToString();

            foreach (var town in towns)
            {
                Console.WriteLine(town.Name);
            }

            sw.Restart();
            towns = db.Employees
                .Select(emp => emp.Address)
                .Select(town => town.Town)
                .Where(town => town.Name == "Sofia");

            foreach (var town in towns)
            {
                Console.WriteLine(town.Name);
            }

            sw.Stop();
            secondResult = sw.Elapsed.ToString();

            Console.WriteLine("Time with ToList: {0}", firstResult);
            Console.WriteLine("Time without ToList: {0}", secondResult);
        }