The EntitySpaces Community

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

Deleting a record without first loading it

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

    Deleting a record without first loading it

    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.
View as RSS news feed in XML