Show / Hide Table of Contents

    IDataStore<TModel>.Sum(Func<TModel, double?> selector) Method

    .NET Standard 2.x

    Computes the sum of a sequence of double? values that are obtained by invoking a transform function on each row of the primary buffer in DataStore.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

    double? Sum(Func<TModel, double?> selector);
    

    Parameters

    selector Func<TModel, double?>

    A transform function to apply to each row.

    Returns

    Nullable<Double>

    The sum of the sequence of values.

    Examples

    The following code example calculates the sum of the values in the budget column.

    using Appeon.ApiDoc.Models;
    using DWNet.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStore_GenericExamples
    {
        public class SumExample
        {
            private readonly SchoolContext _context;
    
            public SumExample(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);
    
                // Retrieves rows from the database for datastore.
                datastore.Retrieve();
    
                Console.WriteLine("After Retrieve, Rowcount: {0}", datastore.RowCount);
    
                // Calculates the sum of the budget column
                double? sumvalue = datastore.Sum(m => (double?)m.Budget);
    
                Console.WriteLine("The sum of Budget is: {0}", sumvalue);
    
                /*This code produces the following output:
                
                After Retrieve, Rowcount: 4
                The sum of Budget is: 790000.0000
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Back to top Generated by Appeon