IDataStore.GetModelByRowId<TModel>(int rowid) Method
.NET Standard 2.x
Gets the TModel
object of a row according to the unique row identifier associated with that row.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
TModel GetRowByRowId<TModel>(int rowid);
Type Parameters
TModel
The type of a model
class that matches with the current DataObject
.
Parameters
rowid
System.Int32
A number specifying the row identifier for which you want to get the associated TModel
object.
Returns
TModel
Returns the TModel
object of the row in the buffer. Returns null
if no row is found.
Remarks
This method allows you to use a unique row identifier to retrieve the TModel
object associated with that row. The row identifier is not affected by operations (such as Insert, Delete, or Filter) that might change the original order (and consequently the TModel
object) of the rows in the DataStore.
The row identifier is relative to the DataStore that currently owns the row.
Examples
The following code example demonstrates how to get row according to the unique row identifier.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStoreExamples
{
public class GetModelByRowIdExample
{
private readonly SchoolContext _context;
public GetModelByRowIdExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example1()
{
// Instantiates a DataStore object with datawindow: d_person_with_dwcompute.
var datastore = new DataStore("d_person_with_dwcompute", _context);
datastore.Retrieve();
// Sets the sort criterion with PersonIDs in descending order.
datastore.SetSort("personid desc");
// Sorts the DataStore according to the sort criterion you have set.
datastore.Sort();
// Gets the clone of the first row.
var person = datastore.GetModel<D_Person_With_Dwcompute>(0);
Console.WriteLine(
"Row = 0, Person ID: {0}; FirstName: {1}; LastName: {2}; Compute_Fullname: {3};",
person.Personid, person.Firstname, person.Lastname, person.Compute_Fullname);
// Gets the clone of a row according to the unique row identifier.
person = datastore.GetModelByRowId<D_Person_With_Dwcompute>(0);
Console.WriteLine(
"Rowid = 0, Person ID: {0}; FirstName: {1}; LastName: {2}; Compute_Fullname: {3};",
person.Personid, person.Firstname, person.Lastname, person.Compute_Fullname);
/*This code produces the following output:
Row = 0, Personid: 34; Firstname: Roger; Lastname: Van Houten; Compute_Fullname; null;
Rowid = 0, Personid: 1; Firstname: Kim; Lastname: Abercrombie; Compute_Fullname: null;
*/
}
}
}
Example Refer To
Model Class: D_Person_With_Dwcompute
DataWindow File: D_Person_With_Dwcompute
Applies to
.NET Standard
2.x