There are two ways to do CRUD in Entity Framework.
Connected Scenario
Disconnected Scenario
CRUD Operations in the connected scenario is very easy to do. Because, in Connected Scenario, context will be automatically updated.
Note
By default,in Connected Scenario, AutoDetectedChangesEnabled property is set to True .
Examples
Following code has to be written when working with the connected scenario.
[csharp]
using (var context = new EmployeeDBEntities())
{
var EmpList = context.Students.ToList<Student>();
//create operation
context.Employees.Add(new Employee() { Name = "New Employee" });
//Update operation
Employee EmployeeToUpdate = EmpList.Where(e => e.Name == "emp1").FirstOrDefault<Employee>();
EmployeeToUpdate.Name = "Edited emp1";
//delete operation
context.Employees.Remove(EmpList.ElementAt<Employee>(0));
//Executing Insert, Update and Delete
context.SaveChanges();
}[/csharp]
If the operations are done within the DBset, then only the changes will be detected. If done changes out of the context, then the changes will not be detected.