IDataStore<TModel>.GetForUpdate(Predicate<TModel> predicate) Method
.NET Standard 2.x
Obtains the TModel
object according to the specified condition.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
TModel GetForUpdate(Predicate<TModel> predicate);
Parameters
predicate
Predicate<TModel>
A Predicate<TModel>
that you want to use as the search criteria.
Returns
TModel
Returns the TModel
object which contains the data for the row found.
It returns null
if no row is found.
Remarks
This method makes a shallow copy of the data, therefore, any changes made to this TModel
will affect the data source. To make a deep copy of the data, refer to GetModel. If multiple rows satisfy the condition, the first row will be returned.
The index number starts from 0, which is consistent with C#.
Examples
The following code example demonstrates how to get data from a Predicate<TModel>
object.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStore_GenericExamples
{
public class GetForUpdateExample
{
private readonly SchoolContext _context;
public GetForUpdateExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example2()
{
// Instantiates a DataStore object with datawindow: d_department.
var datastore = new DataStore<D_Department>(_context);
datastore.Retrieve();
// Gets the reference of the first row.
var department = datastore.GetForUpdate(a => a.Departmentid == 1);
Console.WriteLine("Department ID: {0},Department Name: {1}",
department.Departmentid, department.Name);
/*This code produces the following output:
Department ID: 1;
Department Name: Engineering
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department