Ejemplo n.º 1
0
 public void Delete(int id)
 {
     using (var ctx = new SchoolModelContext())
     {
         var entityToDelete = ctx.Instructors.FirstOrDefault(i => i.Id == id);
         ctx.Instructors.Remove(entityToDelete);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 2
0
 public void Delete(int id)
 {
     using (var ctx = new SchoolModelContext())
     {
         var entityToDelete = ctx.Courses.FirstOrDefault(c => c.Id == id);
         ctx.Courses.Remove(entityToDelete);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public List<Student> GetByWhere(Expression<Func<Student, bool>> filter)
 {
     using (var ctx = new SchoolModelContext())
     {
         return ctx.Students.Where(filter)
             .Include(s => s.Enrollments.Select(e => e.Course.Instructor))
             .ToList();
     }
 }
Ejemplo n.º 4
0
 public Student GetById(int id)
 {
     using (var ctx = new SchoolModelContext())
     {
         return ctx.Students.Where(s => s.Id == id)
             .Include(s => s.Enrollments.Select(e => e.Course.Instructor))
             .SingleOrDefault();
     }
 }
Ejemplo n.º 5
0
 public List<Student> GetAll()
 {
     using (var ctx = new SchoolModelContext())
     {
         return ctx.Students
             .Include(s => s.Enrollments.Select(e => e.Course.Instructor))
             .ToList();
     }
 }
Ejemplo n.º 6
0
 public List<Course> GetAll()
 {
     using (var ctx = new SchoolModelContext())
     {
         return ctx.Courses
             .Include(c => c.Instructor)
             .Include(c => c.Enrollments.Select(e => e.Student))
             .ToList();
     }
 }
Ejemplo n.º 7
0
 public List<Instructor> GetByWhere(Expression<Func<Instructor, bool>> filter)
 {
     using (var ctx = new SchoolModelContext())
     {
         return ctx.Instructors.Where(filter)
             .Include(i => i.TeachingCourses.Select(c => c.Enrollments.Select(e => e.Student)))
             .Include(i => i.TeachingCourses.Select(c => c.Enrollments.Select(e => e.Course)))
             .ToList();
     }
 }
Ejemplo n.º 8
0
 public Instructor GetById(int id)
 {
     using (var ctx = new SchoolModelContext())
     {
         return ctx.Instructors.Where(i => i.Id == id)
             .Include(i => i.TeachingCourses.Select(c => c.Enrollments.Select(e => e.Student)))
             .Include(i => i.TeachingCourses.Select(c => c.Enrollments.Select(e => e.Course)))
             .SingleOrDefault();
     }
 }
Ejemplo n.º 9
0
 public List<Instructor> GetAll()
 {
     using (var ctx = new SchoolModelContext())
     {
         return ctx.Instructors
             .Include(i => i.TeachingCourses.Select(c => c.Enrollments.Select(e => e.Student)))
             .Include(i => i.TeachingCourses.Select(c => c.Enrollments.Select(e => e.Course)))
             .ToList();
     }
 }
Ejemplo n.º 10
0
 public List<Course> GetAllIncluding(params Expression<Func<Course, object>>[] includeProperties)
 {
     using (var ctx = new SchoolModelContext())
     {
         IQueryable<Course> query = ctx.Courses;
         foreach (var includeProperty in includeProperties)
         {
             query = query.Include(includeProperty);
         }
         return query.ToList();
     }
 }
Ejemplo n.º 11
0
        public void InsertOrUpdate(Course t)
        {
            using (var ctx = new SchoolModelContext())
            {
                ctx.UpdateGraph(t,
                    map =>
                        map.OwnedEntity(c => c.Instructor)
                            .OwnedCollection(c => c.Enrollments, with => with.OwnedEntity(s => s.Student))
                    );

                ctx.SaveChanges();
            }
        }
Ejemplo n.º 12
0
        public void InsertOrUpdate(Instructor t)
        {
            using (var ctx = new SchoolModelContext())
            {
                ctx.UpdateGraph(t,
                    map =>
                        map.OwnedCollection(i => i.TeachingCourses,
                            with1 =>
                                with1.OwnedCollection(o => o.Enrollments,
                                    with2 => with2.OwnedEntity(e => e.Student).OwnedEntity(e => e.Course)))

                    );

                ctx.SaveChanges();
            }
        }