static void TestConcurrency() { Student student = null; using (var context = new PetDemoEntities(PetDataConnectionStringBuilder.GetConnectionString())) { student = context.Students.First(); } //Edit student name Console.Write("Enter New Student Name:"); student.StudentName = Console.ReadLine(); //Assigns student name from console using (var context = new PetDemoEntities(PetDataConnectionStringBuilder.GetConnectionString())) { try { context.Entry(student).State = EntityState.Modified; context.SaveChanges(); Console.WriteLine("Student saved successfully."); } catch (DbUpdateConcurrencyException ex) { Console.WriteLine("Concurrency Exception Occurred."); } } }
static void TestEnum() { Teacher newTeacher = new Teacher(); newTeacher.TeacherName = "Jinpyo Kim"; newTeacher.TeacherType = TeacherType.Contract; using (var db = new PetDemoEntities(PetDataConnectionStringBuilder.GetConnectionString())) { db.Entry(newTeacher).State = newTeacher.TeacherId == 0 ? EntityState.Added : EntityState.Modified; //db.Teachers.Add(newTeacher); db.SaveChanges(); } }