Show / Hide Table of Contents

    IDataStore.Max<TModel, TResult>(Func<TModel, TResult> selector, Predicate<TModel> predicate) Method

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

    0.5.0-alpha

    1.0.1 (current)

    Invokes a transform function on each row (that satisfies the condition specified by Predicate<TModel>) in the primary buffer of the DataStore and returns the maximum result value.

    Namespace: PowerBuilder.Data

    Assembly: PowerBuilder.Data.dll

    Syntax

      public TResult Max<Tmodel, TResult>(Func<Tmodel, TResult> selector, Predicate<Tmodel> predicate);
    

    Type Parameters

    TModel

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

    TResult

    The type of the value returned by selector.

    Parameters

    selector System.Func<TModel,TResult>

    A transform function to apply to each row.

    predicate System.Predicate<TModel>

    A function to evaluate each row for a condition.

    Returns

    TResult

    The maximum value.

    Examples

    The following code example demonstrates how to get the maximum value for budget from the Department table which meets the criteria Departmentid > 3.

    using PowerBuilder.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class MaxExample
        {
            private SchoolContext _context;
    
            public MaxExample(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();
    
                // Get the maximum value for budget where departmentid > 3
                // The largest budget that meets the criteria is 250000.00
                decimal maxBudget = datastore.Max<D_Department, decimal>
                    (d => d.Budget, d => d.Departmentid > 3);
    
                Console.WriteLine("Max Budget: {0}",
                                   maxBudget);
    
                /*This code produces the following output:
                 
                Max Budget: 250000.00
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon