コード例 #1
0
ファイル: Form1.cs プロジェクト: anuragraj94/Entity-Framework
 public List <StudentDetail> Display()   // Display Method is a common method to bind the Student details in datagridview after save,update and delete operation perform.
 {
     using (StudentInformationEntities _entity = new StudentInformationEntities())
     {
         return(_entity.StudentDetails.ToList());
     }
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: anuragraj94/Entity-Framework
        public bool SaveStudentDetails(StudentDetail Stu) // calling SaveStudentMethod for insert a new record
        {
            bool result = false;

            using (StudentInformationEntities _entity = new StudentInformationEntities())
            {
                _entity.StudentDetails.Add(Stu);
                _entity.SaveChanges();
                result = true;
            }
            return(result);
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: anuragraj94/Entity-Framework
        public bool DeleteStudentDetails(StudentDetail Stu) // DeleteStudentDetails method to delete record from table
        {
            bool result = false;

            using (StudentInformationEntities _entity = new StudentInformationEntities())
            {
                StudentDetail _student = _entity.StudentDetails.Where(x => x.Id == Stu.Id).Select(x => x).FirstOrDefault();
                _entity.StudentDetails.Remove(_student);
                _entity.SaveChanges();
                result = true;
            }
            return(result);
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: anuragraj94/Entity-Framework
        public bool UpdateStudentDetails(StudentDetail Stu) // UpdateStudentDetails method for update a existing Record
        {
            bool result = false;

            using (StudentInformationEntities _entity = new StudentInformationEntities())
            {
                StudentDetail _student = _entity.StudentDetails.Where(x => x.Id == Stu.Id).Select(x => x).FirstOrDefault();
                _student.Name   = Stu.Name;
                _student.Age    = Stu.Age;
                _student.City   = Stu.City;
                _student.Gender = Stu.Gender;
                _entity.SaveChanges();
                result = true;
            }
            return(result);
        }