Documentation
SolutionDeveloperComplianceProjects
  • Getting Started
  • Technology
    • Application Framework
    • Object-Relational Mapping
    • Security Framework
    • Architecture Pattern
    • API Management
  • Environment
    • Development Tool
    • Database Server
    • Web Server
  • PRESENTATION
    • Design Material
    • HTML Helpers
    • Icon Images
    • Custom CSS
    • JQuery Plugin
      • DataTables
      • Tabs
      • Date Picker
      • Calendar
      • Chart
      • Treeview
    • Client Script
      • Open Modal
      • Close Modal
      • Handle return data
      • Load Content
      • Change Hash
      • Change Title
      • Get actual Hash
      • Get Content
      • Update Content
      • Delete Content
      • Get Partial Content
      • Get Partial Content Async
      • Update Partial Content
      • Update Partial Content Async
      • Delete Partial Content
      • Get Action
      • Update Action
      • Delete Action
      • Cascading Dropdown
      • Display Document
    • MVC View
  • BACKEND
    • Base Controller
    • Controller
    • Base Model
    • View Model
    • Class Utility
      • Constant Values
      • Global Properties
      • Option Helper
      • Setting Helper
    • Data Repository
      • Read Columns
      • Read All Columns
      • Read First Record
      • Read by Primary Key
      • Find Record
      • Insert Record
      • Update Record
      • Delete Entity
      • Delete by Criteria
      • Delete by Primary Key
      • Counting Record
      • Check Exist
      • Generate Row-Id
    • Unit Of Work
    • Data Entity
  • Application Features
    • Account Management
    • Navigation Editor
    • Access Control
  • Examples
    • Simple Page
    • Master Detail
    • Editor Template
Powered by GitBook
On this page
  • Syntax
  • Arguments
  • Description
  • Examples
  • Example 1: Updating a single record
  • Example 2: Updating multiple records
  1. BACKEND
  2. Data Repository

Update Record

Syntax

Update(entity);

Arguments

entity

T

Instance of to-be-updated record containing the intended changes.

This parameter must not be empty.

Description

Updates an existing record of a repository by taking an instance of the record with changed values as input and updating the record in the repository accordingly.

It can only update one record at a time but if the same changes should be done for multiple records, you can use loops to automate the process to save time (see Example 2).

Examples

Example 1: Updating a single record

  1. load the record you wish to update into a variable, e.g. by using "GetByID" or "Find"

  2. update the specific attributes you wish to change by accessing those attributes using the dot operator on the variable and assigning them the new values

  3. confirm the update by calling this function "Update" with the variable as input

The following program illustrates this process:

//1.Step: load data
var orderChange = repo.GetByID("EU00789980");

//2.Step: update attributes
orderChange.DueDate = DateTime.Today;
orderChange.IsPlan = true;
orderChange.ChangedBy = "user.name";

//3.Step: confirm update
repo.Update(orderChange);

The function will update the data of the specific record in the repository that has the Primary Key value "EU00789980" according to the changes made in the variable.

Example 2: Updating multiple records

  1. load all the records you wish to update into a variable. e.g. by using "Get"

  2. loop through the loaded records and, within the loop, update the specific attributes you wish to change by accessing those attributes using the dot operator on the loop variable and assigning them the new values

  3. confirm the update by calling this function "Update" within the loop

The following program illustrates this process:

//1.Step: load data
var orderBatch = repo.Get(x => x.ProductID == "ADAM-567-BTO" && x.IsPlan == false);

//2.Step: update attribute
foreach(var item in orderBatch)
{
    item.Quantity = 10;
    item.ChangedDate = DateTime.Now;
    item.ChangedBy = "user.name";

//3.Step: confirm change
    repo.Update(item);
}

At the end of every iteration of the loop, the function will update the data of the currently processed record according to the changes made in the loop variable.

PreviousInsert RecordNextDelete Entity

Last updated 2 years ago