public void AddEmployee(EmpTable emp) { //No SQL Statements, everything is OOP.... var context = new MyDBEntities(); context.EmpTables.Add(emp); //Adds to the Collection... context.SaveChanges(); //Commit to the database.. }
public void UpdateEmployee(EmpTable emp) { var context = new MyDBEntities(); var selected = context.EmpTables.FirstOrDefault((e) => e.EmpID == emp.EmpID); selected.Empname = emp.Empname; selected.EmpAddress = emp.EmpAddress; selected.EmpSalary = emp.EmpSalary; context.SaveChanges(); }
public void DeleteEmployee(int id) { var context = new MyDBEntities(); var emp = context.EmpTables.FirstOrDefault((e) => e.EmpID == id); if (emp == null) { throw new Exception("No Employee was found to delete"); } context.EmpTables.Remove(emp); context.SaveChanges(); }