Entity Framework - SPLessons

Entity Framework CRUD in Connected Scenario

Home > Lesson > Chapter 11
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Entity Framework CRUD in Connected Scenario

Entity Framework CRUD in Connected Scenario

shape Description

There are two ways to do CRUD in Entity Framework. CRUD Operations in the connected scenario is very easy to do. Because, in Connected Scenario, context will be automatically updated.

shape 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.