Deleting an Employee without first loading it . This is a nice to have
Code:
Employee emp = new Employee();
emp.AddNew(); // Merely creates the DataTable = RowState = Added
emp.EmployeeID = 1;
emp.AcceptChanges(); // Mark the record as DataRowState.Unchanged
emp.MarkAsDeleted(); // Mark the records as DataRowState.Deleted
emp.Save();
The preferred way is still:
Code:
Employee emp = new Employee();
e.LoadByPrimaryKey(1);
emp.MarkAsDeleted(); // Mark the records as DataRowState.Deleted
emp.Save();
This is the perferred way for for several reasons. First, down the road you
encounter bottlenecks, but discover that the solution is to switch from your
default of DynamicSQL to StoredProcedure. If you used the preferred approach you
have a 1 line change to your config file and you are good to go. The
non-preferred method doesn't allow for the use of stored procedures and relies
entirely on dynamic sql.