Example #1
0
 public void RemoveAll()
 {
     using (StudentsEntities context = new StudentsEntities())
     {
         context.Database.ExecuteSqlCommand("TRUNCATE TABLE Students");
     }
 }
Example #2
0
 public void AddStudent(Student s)
 {
     using (StudentsEntities context = new StudentsEntities())
     {
         context.Students.Add(s);
         context.SaveChanges();
     }
 }
Example #3
0
        public List <Student> GetStudents()
        {
            List <Student> result = new List <Student>();

            using (StudentsEntities context = new StudentsEntities())
            {
                result = context.Students.ToList();
            }
            return(result);
        }
Example #4
0
        public Student GetStudentById(string id)
        {
            Student result = new Student();

            using (StudentsEntities context = new StudentsEntities())
            {
                result = context.Students.FirstOrDefault(s => s.Id == id);
            }
            return(result);
        }
Example #5
0
 public void DeleteStudentById(string id)
 {
     using (StudentsEntities context = new StudentsEntities())
     {
         foreach (Student s in context.Students)
         {
             if (s.Id == id)
             {
                 context.Students.Remove(s);
             }
         }
         context.SaveChanges();
     }
 }