static void RemoveItem(Context context) { var employee = context.Employees.FirstOrDefault(e => e.Name.StartsWith("A")); if (employee != null) { context.Employees.Remove(employee); context.SaveChanges(); } }
static void AddItems(Context context) { var departmentSD = new Department { Name = "Software development" }; var departmentHR = new Department { Name = "HR" }; context.Departments.Add(departmentSD); context.Departments.Add(departmentHR); context.Employees.Add(new Employee { Name = "Sergey Efremov", Department = departmentSD }); context.Employees.Add(new Employee { Name = "Andrey Ivanov", Department = departmentHR }); context.SaveChanges(); }
static void EditItem(Context context) { var employee = context.Employees.First(e => e.Name.StartsWith("A")); employee.Name = "Sergey"; context.SaveChanges(); }