public static void BasicEntitySample() { var employees = new SampleData().GetEmployees(); var empdata = employees.Where(e => e.Department == "Sales"); }
public static void FirstVsFirstOrDefault() { var employees = new SampleData().GetEmployees(); ////throws error //var empdata = employees.Where(e => e.EmployeeId == 200).First(); var empdata1 = employees.Where(e => e.EmployeeId == 200).FirstOrDefault(); if (empdata1 == null) { Console.WriteLine("Employee not found"); } Console.Read(); }
public static void IndexedQueries() { var employees = new SampleData().GetEmployees(); //var selectedEmps = employees.Where(emp => emp.Department == "Sales"); var selectedEmps = employees.Where((emp, index) => ((index != 0) ? true : false)); foreach (var emp in selectedEmps) { Console.WriteLine("Employee Name: " + emp.EmployeeName); } Console.Read(); }