コード例 #1
0
        public static void GroupBy_OrderBy_cantidad()
        {
            Console.WriteLine(" GROUP BY FIELD");
            Console.WriteLine(" Cantidad de alumnos por carrera");

            var alumnosPorCarrera = new AlumnoSC()
                                    .GroupAlumosByCarrera()
                                    .Select(g => new
            {
                carrera = g.Key,
                total   = g.Count()
            }).ToList();

            alumnosPorCarrera.ForEach(a =>
            {
                Console.WriteLine(" - " + a.carrera + ": " + a.total);
            });
            Console.WriteLine();


            Console.WriteLine(" ORDER BY FIELD");
            Console.WriteLine(" Ordenar la consulta anterior de mayor a menor cantidad");

            alumnosPorCarrera
            .OrderByDescending(a => a.total)
            .ToList().ForEach(g =>
            {
                Console.WriteLine(" - " + g.carrera + ": " + g.total);
            });
        }
コード例 #2
0
        public static void Select_alumnos()
        {
            Console.WriteLine("\n\n SELECT FROM TABLE AS");
            Console.WriteLine(" Alumnos Registrados:\n\n");

            List <AlumnoDTO> alumnos = new AlumnoSC()
                                       .GetAllAlumnos()
                                       .Select(a => new AlumnoDTO
            {
                Matricula       = a.matricula_alumno,
                Nombre          = a.nombre_alumno,
                ApellidoPaterno = a.apellido_paterno_alumno,
                ApellidoMaterno = a.apellido_materno_alumno
            }).ToList();

            StringBuilder datos = new StringBuilder();

            datos.Append(String.Format("{0,-51} {1,11}\n", " Nombre", "Matricula"));
            datos.Append("\n");

            alumnos.ForEach(a =>
            {
                string name = " " + a.Nombre + " " + a.ApellidoPaterno + " " + a.ApellidoMaterno;
                datos.Append(String.Format("{0,-51} {1,11}\n", name, a.Matricula));
            });

            Console.WriteLine(datos);
        }