Show / Hide Table of Contents

    IDataStore.GetModelByRowId<TModel>(int rowid, bool calcCompute) 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

    public TModel GetModelByRowId<TModel>(int rowid, bool calcCompute);
    

    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.

    calcCoompute System.Boolean

    Whether to calculate columns with DwCompute attribute.

    Returns

    TModel

    Returns the TModel object of the row in the buffer. Returns null if no row is found.

    Examples

    The following code example demonstrates how to get row according to the unique row identifier and using the calcCompute parameter.

    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 Example2()
            {
                // 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, true);
    
                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: Kim Abercrombie;
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Person_With_Dwcompute
    DataWindow File: D_Person_With_Dwcompute

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon