Beispiel #1
0
        private static void ReadData()
        {
            using (var context = new Employees.employeesContext())
            {
                DateTime dateTime         = new DateTime(2001, 01, 01);
                var      orderedQueryable = from e in context.Employees
                                            join s in context.Salaries
                                            on e.EmpNo equals s.EmpNo
                                            where s.FromDate >= dateTime
                                            group s by e.EmpNo into salaryGroup
                                            select new
                {
                    EmployeeId = salaryGroup.Key,
                    AvgSalary  = salaryGroup.Average(x => x.Salary)
                };

                foreach (var message in from result in orderedQueryable.OrderByDescending((x) => x.AvgSalary)
                         let message = new StringBuilder()
                                       .AppendLine($"EmployeeID: {result.EmployeeId}, AvgSalary: {result.AvgSalary}")
                                       select message)
                {
                    Console.WriteLine(message.ToString());
                }
            }
        }
Beispiel #2
0
        private static List <salaryGroupData> CommonSQLWhere()
        {
            using (var context = new Employees.employeesContext())
            {
                DateTime dateTime         = new DateTime(2001, 01, 01);
                var      orderedQueryable = from e in context.Employees
                                            join s in context.Salaries
                                            on e.EmpNo equals s.EmpNo
                                            where s.FromDate >= dateTime
                                            select new salaryGroupData {
                    EmployeeId = e.EmpNo, SalaryCalculation = s.Salary
                };

                return(orderedQueryable.ToList());
            }
        }