Table of Contents


Updating Records

The Edit operation modifies one or more Entity records in the database. This method accepts one record, or more than 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 erase 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 the 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 committed 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.