Beispiel #1
0
        private static void displayAllNames()
        {
            var rep   = RepositoryClass.GetAllEmployees();
            var names = from emp in rep
                        select emp.EmpName;

            foreach (var name in names)
            {
                Console.WriteLine(name);
            }
        }
Beispiel #2
0
        private static void displayNamesFromBangalore()
        {
            var records = RepositoryClass.GetAllEmployees();
            var names   = from emp in records
                          where emp.EmpAddress == "Bangalore"
                          select emp.EmpName;

            foreach (var name in names)
            {
                Console.WriteLine(name);
            }
        }
Beispiel #3
0
        private static void displayNamesByOrder()
        {
            var records = RepositoryClass.GetAllEmployees();
            var names   = from emp in records
                          orderby emp.EmpName descending
                          select emp.EmpName;

            foreach (var name in names)
            {
                Console.WriteLine(name);
            }
        }
Beispiel #4
0
        private static void displayNamesAndAddresses()
        {
            var records = RepositoryClass.GetAllEmployees();
            var data    = from emp in records
                          select new { FullName = emp.EmpName, City = emp.EmpAddress };

            //creating an object using new operator with no name is called Anonymous types.
            foreach (var info in data)
            {
                Console.WriteLine(info.FullName);
            }
        }
Beispiel #5
0
        private static void displayNamesByGroups()
        {
            var records = RepositoryClass.GetAllEmployees();
            var groups  = from emp in records
                          group new { emp.EmpName, emp.EmpAddress } by emp.EmpAddress into g
            orderby g.Key
            select g;

            //An Array of Arrays....
            foreach (var group in groups)
            {
                Console.WriteLine("People working in " + group.Key);
                foreach (var emp in group)
                {
                    Console.WriteLine(emp);
                }
                Console.WriteLine("\n\n\n");
            }
        }
Beispiel #6
0
        private static void joinExample()
        {
            var employees = RepositoryClass.GetAllEmployees();
            var depts     = RepositoryClass.GetAllDepts();
            var data      = from emp in employees
                            join dept in depts on emp.DeptID equals dept.DeptID
                            orderby emp.EmpName
                            group new { emp.EmpName, dept.DeptName }  by dept.DeptName into gr
            orderby gr.Key descending
            select gr;

//            foreach (var info in data) Console.WriteLine(info);
            foreach (var gr in data)
            {
                Console.WriteLine("Groups under " + gr.Key);
                foreach (var emp in gr)
                {
                    Console.WriteLine(emp);
                }
            }
        }