public static void Add(Employee employee) { var context = new SoftUniEntities(); context.Employees.Add(employee); context.SaveChanges(); Console.WriteLine("Employee has been added."); }
public static void Modify(int employeeId, string property, object value) { var context = new SoftUniEntities(); var selectedEmployee = context.Employees.Find(employeeId); selectedEmployee.GetType().GetProperty(property).SetValue(selectedEmployee, value); context.SaveChanges(); Console.WriteLine("Employee has been modified."); }
public static void Delete(int employeeId) { var context = new SoftUniEntities(); var selectedEmployee = context.Employees.Find(employeeId); context.Employees.Remove(selectedEmployee); context.SaveChanges(); Console.WriteLine("Employee has been deleted."); }
static void Main() { var contextOne = new SoftUniEntities(); var empOne = contextOne.Employees.Find(1); empOne.FirstName = "Mincho"; var contextTwo = new SoftUniEntities(); var empTwo = contextTwo.Employees.Find(1); empTwo.FirstName = "Zdravko"; contextOne.SaveChanges(); contextTwo.SaveChanges(); //result with [Concurrency Mode] = None: second win: the first name is set to Zdravko //result with [Concurrency Mode] = Fixed: first win: the first name is set to Mincho }