public static void Suma() { using (var ctx = new alumno14Entities()) { var data = ctx.Curso.Sum(o => o.duracion); Console.WriteLine(data); } }
public static void SubSelect() { using (var ctx = new alumno14Entities()) { var data = ctx.Alumno.Find(1).Curso.Select(o => o.ProfesorCurso.Select(oo=>oo.Profesor)); //ctx.Alumno.Where(o => o.Curso.Select(oo => oo.inicio > DateTime.Now)); } }
public static void SinLazy() { using (var ctx = new alumno14Entities()) { ctx.Configuration.LazyLoadingEnabled = false; var alu = ctx.Alumno.Where(o => o.dni.Contains("a")); } }
public static void ConsultaSimple() { //using ->Ciera la conexion using (var ctx = new alumno14Entities()) { var data = ctx.Profesor.Where(o => o.nombre.Contains("Mirel")); foreach (var profesor in data) { Console.WriteLine(profesor); } } }
public static void BusquedaEnlazada() { using (var ctx = new alumno14Entities()) { var cursos = ctx.ProfesorCurso.Where(o => o.idProfesor == 1) .Select(o => o.Curso);//Solo un campo cursos = cursos.Where(o => o.inicio == DateTime.Now).OrderBy(o => o.duracion); var rf=cursos.Where(o => o.Alumno.Select(oo => oo.dni).Contains("1")).ToList(); Console.WriteLine(cursos); } }
public static void ObjetoDinamico() { using (var ctx = new alumno14Entities()) { var data = ctx.Profesor.Where(o => o.nombre.Contains("Mirel")) .Select(o => new {o.nombre,o.edad});//Varios campos //.Select(o => new {Denominacion=o.nombre, Edad=o.edad}); //select nombre,edad from Profesor where nombre="Mirel"; foreach (var profesor in data) { Console.WriteLine(profesor); } } }