コード例 #1
0
 public virtual void Delete(TEntity entityToDelete)
 {
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
     dbSet.Remove(entityToDelete);
 }
コード例 #2
0
        public bool DeleteStudent(string emailAddress)
        {
            //tblStudent student = _context.tblStudent.Find(EmailAddress);
            tblStudent removedStudent = (from student in _context.tblStudent
                                         where student.EmailAddress == emailAddress
                                         select student).FirstOrDefault();

            var removedStudentHistory = from studentHistory in _context.tblStudentHistory
                                        where studentHistory.StudentID == removedStudent.StudentID
                                        select studentHistory;

            tblUser removedUser = (from user in _context.tblUser
                                   where user.EmailAddress == removedStudent.EmailAddress
                                   select user).FirstOrDefault();

            //tblStudent removedStudent = getStudent;

            //Removing Student
            _context.Entry(removedStudent).State = System.Data.Entity.EntityState.Deleted;

            //Removing Student's History
            foreach (var entry in removedStudentHistory)
            {
                _context.Entry(entry).State = System.Data.Entity.EntityState.Deleted;
            }

            //Removing the user for that student
            _context.Entry(removedUser).State = System.Data.Entity.EntityState.Deleted;

            //_context.tblStudentHistory.Remove(removedStudentHistory);
            //_context.tblStudent.Remove(removedStudent);
            //_context.tblUser.Remove(removedUser);

            _context.SaveChanges();

            //if ()
            return(true);
            //else
            //    return false;
        }
コード例 #3
0
 public void UpdateCollege(tblCollege college)
 {
     _context.Entry(college).State = EntityState.Modified;
 }