IDataStore.Sum<TModel>(Func<TModel, decimal> selector, Predicate<TModel> predicate) Method
.NET Standard 2.x
Computes the sum of a sequence of decimal
values that are obtained by invoking a transform function on each row (filtered by a Predicate<TModel>
object) of the primary buffer in DataStore.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public decimal Sum<TModel>(Func<TModel, decimal> selector, Predicate<TModel> predicate);
Type Parameters
TModel
The type of a model
class that matches with the current DataObject
.
Parameters
selector
System.Func<TModel,System.Decimal>
A transform function to apply to each row.
predicate
System.Predicate<TModel>
A function to evaluate each row in the primary buffer for a condition.
Returns
System.Decimal
The sum of the sequence of values.
Examples
The following code example calculates the sum of those values (which are greater than 200000) in the budget column.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStoreExamples
{
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 budget whose value is greater than 200000.
decimal sumvalue = datastore.Sum<D_Department>(
m => m.Budget,
m => m.Budget > 200000);
Console.WriteLine("The sum of budget greater than 200000 is: {0}",
sumvalue);
/*This code produces the following output:
After Retrieve, Rowcount: 4
The sum of budget greater than 200000 is: 470000.0000
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x