public static void Main() { var telerikAcademy = new TelerikAcademyEntities(); telerikAcademy.Departments.Count(); var stringBuilder = new StringBuilder(); var stopwatch = new Stopwatch(); stopwatch.Start(); var withoutInclude = telerikAcademy.Employees; UseTheData(stringBuilder, withoutInclude); stopwatch.Stop(); var firstResult = stopwatch.Elapsed.ToString(); stopwatch.Restart(); var withInclude = telerikAcademy.Employees.Include("Department").Include("Address.Town"); var resultWithInclude = UseTheData(stringBuilder, withInclude); stopwatch.Stop(); var secondResult = stopwatch.Elapsed.ToString(); Console.WriteLine(resultWithInclude); Console.WriteLine("Time without include: {0}", firstResult); Console.WriteLine("Time with include: {0}", secondResult); }
private static void Main() { var telerikAcademy = new TelerikAcademyEntities(); var stopwatch = new Stopwatch(); var stringBuilder = new StringBuilder(); stopwatch.Start(); var towns = telerikAcademy.Employees.ToList() .Select(emp => emp.Address) .ToList() .Select(town => town.Town) .ToList() .Where(town => town.Name == "Sofia"); stopwatch.Stop(); var firstResult = stopwatch.Elapsed.ToString(); UseTowns(towns, stringBuilder); stopwatch.Restart(); towns = telerikAcademy.Employees.Select(emp => emp.Address) .Select(town => town.Town) .Where(town => town.Name == "Sofia"); UseTowns(towns, stringBuilder); stopwatch.Stop(); var secondResult = stopwatch.Elapsed.ToString(); Console.WriteLine("Time with ToList: {0}", firstResult); Console.WriteLine("Time without ToList: {0}", secondResult); }
public static void Main(string[] args) { var context = new TelerikAcademyEntities(); var format = "\nName: {0} {1} {2} \nDepartment: {3} \nTown: {4}"; var stopwatch = new Stopwatch(); stopwatch.Start(); foreach (var employee in context.Employees.Include("Department").Include("Address.Town")) { Console.WriteLine(format, employee.FirstName, employee.MiddleName, employee.LastName, employee.Department.Name, employee.Address.Town.Name); } stopwatch.Stop(); Console.ForegroundColor = ConsoleColor.Yellow; var timerFormat = "\nTime: {0} \nTotal Queries: {1}"; var totalQueries = "1, see the EmployeesViewerWithInclude.xlsx"; Console.WriteLine(timerFormat, stopwatch.Elapsed, totalQueries); }
public static void Main(string[] args) { var context = new TelerikAcademyEntities(); var stopwatch = new Stopwatch(); stopwatch.Start(); const string chosenTown = "sofia"; var employeesFromSofia = context.Employees.Join( context.Addresses, e => e.AddressID, a => a.AddressID, (e, a) => new { TownId = a.TownID } ) .Join( context.Towns, e => e.TownId, t => t.TownID, (e, t) => new { TownName = t.Name } ) .Where(t => t.TownName == chosenTown).ToList(); stopwatch.Stop(); var format = "Execution time: {0} \nTotal Queries: {1}"; var totalQueries = "1, see the EmployeesFromSofia.xlsx"; Console.WriteLine(format, stopwatch.Elapsed, totalQueries); }