The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Updating a record without first loading it

Last post 01-27-2007, 6:50 PM by ESAdmin. 0 replies.
Sort Posts: Previous Next
  •  01-27-2007, 6:50 PM 15

    Updating a record without first loading it

    This example updates an Empoyee without first loading it.

    Code:
    Employees emp = new Employees(); 
    emp.AddNew(); // Merely creates the DataTable = RowState = Added
    emp.EmployeeID = 1;
    emp.AcceptChanges(); // Mark the record as DataRowState.Unchanged
    emp.FirstName = "Direct"; // Any column change marks the record as DataRowState.Modified
    emp.LastName = "Updates";
    emp.Save();

    The perferred way is still:

    Code:
    Employee emp = new Employee(); 
    emp.LoadByPrimaryKey(1);
    emp.FirstName = "Direct";
    emp.LastName = "Updates";
    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. Also, and more importanly, you have no concurrency handling possibiliites in the non-preferred sample.

View as RSS news feed in XML