Developer Guide
Updating Records

    The Edit operation modifies one or more Entity records in the database. This method accepts one record, or more then one record which supports both Lists and Arrays. The example below shows how to update a number of Contact records at once:

     

    //query a number of Contact records
    List<Contact> contacts = Database.Query<Contact>().Limit(5).ToList();
    
    //make modifications
    foreach(Contact c in contacts)
      c.MailingCity="Toronto";
    
    try
    {
       //update the records in database
       Edit(contacts);
    }
    catch(DatabaseException ex)
    {
       //Automatically update the ModelState, so show the validation errors to users. 
       //(ViewMessages control shows the reuslts)
       UpdateModelState(ex);
    
       //usually you want to return the results to the user at this point.
       return View(contacts);
    }
    
    
    Note: In order to update records, you need to query all fields of an Entity. If you use a SELECT call to hand-pick certain fields only, the update call would earse the values from the Database and set them to null.

    Processing in System Mode 

    The Magentrix for Edit operation validates the user's access and verifies that user has "edit" permission. However, in some scenarios, an edit operation should take place regardless of the user's permission; in such cases use the SystemMode flag.

    Edit(contacts, new { SystemMode = true });

     

    Transactional Commit

    If you wish all records to be commited together or rolled back in case of an error, set the AllOrNone flag to true. This flag by default is false.

    Edit(contacts, new { AllOrNone=true });


    See Database Options for more details.