Show / Hide Table of Contents

    IDataStore.LastOrDefault<TModel>() Method

    .NET Standard 2.x | Current Version (1.0.1)

    0.5.0-alpha

    1.0.1 (current)

    Generic method. Returns the last data row of the DataStore. If no data row is found, returns null.

    Namespace: PowerBuilder.Data

    Assembly: PowerBuilder.Data.dll

    Syntax

      public TModel LastOrDefault<TModel>();
    

    Type Parameters

    TModel

    The type of a model class that matches with the current DataObject.

    Returns

    TModel

    Return the TModel object which contains the data of the last row.

    It returns null if no row is found.

    Examples

    The following code example demonstrates how to use the LastOrDefault method to get the last record object in DataStore.

    using PowerBuilder.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class LastOrDefaultExample
        {
            private SchoolContext _context;
    
            public LastOrDefaultExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example1()
            {
                // Instantiates a DataStore object with datawindow: d_department.
                var datastore = new DataStore("d_department", _context);
    
                datastore.Retrieve();
    
                // The last record in the Department table is: 
                // departmentid = 7, name = Mathematics
                var department = datastore.LastOrDefault<D_Department>();
    
                Console.WriteLine("Department ID: {0}; Department Name: {1}",
                                   department.Departmentid, department.Name);
    
                /*This code produces the following output:
                 
                Department ID: 7; Department Name: Mathematics
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon