Beispiel #1
0
        public static void FastToListOperation()
        {
            using (TelerikAcademyEntities context = new TelerikAcademyEntities())
            {
                Stopwatch watch = new Stopwatch();
                watch.Start();

                var sofiaEmployees = context.Employees.Select(e => e).Select(e => e.Address).Select(a => a.Town)
                    .Where(t => t.Name.ToLower() == "sofia");

                Console.WriteLine("Sofia employee count = {0}.", sofiaEmployees.Count());
                watch.Stop();
                Console.WriteLine("Fast operations executed in {0} milliseconds.", watch.Elapsed.Milliseconds);
            }
        }
Beispiel #2
0
        public static void FastEmployeeQuery()
        {
            using (TelerikAcademyEntities context = new TelerikAcademyEntities())
            {
                Stopwatch watch = new Stopwatch();
                watch.Start();
                var employees = from employee in context.Employees.Include("Department").Include("Address").Include("Town")
                                select new
                                {
                                    Name = employee.LastName,
                                    Department = employee.Department.Name,
                                    Town = employee.Address.Town.Name
                                };

                /*foreach (var employee in employees)
                {
                    Console.WriteLine("{0} from department {1} lives in {2}.", employee.Name, employee.Department, employee.Town);
                }*/

                watch.Stop();
                Console.WriteLine("Fast operations executed in {0} milliseconds.", watch.Elapsed.Milliseconds);
            }
        }