Connected Scenario

Disconnected Scenario

CRUD Operation in Connected Scenario

var studentList = db.Students.ToList();

// Perform create operation
db.Students.Add(new Student { StudentName = "New Student" });

// Perform Update operation
var studentToUpdate = studentList
	.FirstOrDefault(s => s.StudentName == "student1");
studentToUpdate.StudentName = "Edited student1";

// Perform delete operation
db.Students.Remove(studentList.First());

// Execute Insert, Update & Delete queries in the database
db.SaveChanges();
var studentList = db.Students.ToList();

// Add student in list
studentList.Add(new Student { StudentName = "New Student" });

// Perform update operation
var studentToUpdate = studentList.
	Where(s => s.StudentName == "Student1").FirstOrDefault();
studentToUpdate.StudentName = "Edited student1";

// Delete student from list
studentList.Remove(studentList.First());

// SaveChanges will only do update operation not add and delete.
db.SaveChanges();

Change Tracking