Skip to content

Instantly share code, notes, and snippets.

@snippe
Created July 26, 2015 03:53
Show Gist options
  • Save snippe/9c51a82cd81215e3256d to your computer and use it in GitHub Desktop.
Save snippe/9c51a82cd81215e3256d to your computer and use it in GitHub Desktop.
DbContext Examples
ObjectContext objectContext = ((IObjectContextAdapter)entities).ObjectContext;
Employee emp1 = new Employee() { EmployeeName = "Employee 1" };
Employee emp2 = new Employee() { EmployeeName = "Employee 2" };
entities.Employees.Add(emp1);
entities.Employees.Add(emp2);
entities.SaveChanges();
objectContext.Detach(emp1);
emp1.EmployeeName = "Employee 1 newName";
emp2.EmployeeName = "Employee 2 newName";
entities.SaveChanges();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment