IDataStore.Avg<TModel>(Func<TModel, decimal> selector) Method
.NET Standard 2.x
Computes the average of a sequence of decimal
values. These values are obtained by invoking a transform function on each row in the primary buffer of the DataStore.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public decimal Avg<TModel>(Func<TModel, decimal> selector);
Type Parameters
TModel
The type of a model
class that matches with the current DataObject
.
Parameters
selector
System.Func<TModel, decimal>
A transform function to apply to each row.
Returns
System.Decimal
The average of the sequence of values.
Examples
The following code example demonstrates how to use the Avg<TModel>(Func<TModel, decimal>)
method to compute the average budget of all departments.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStoreExamples
{
public class AvgExample
{
private readonly SchoolContext _context;
public AvgExample(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();
// This datastore has 4 records
// Values of Budget are:
// 350000.00, 120000.00, 200000.00, 250000.00
// so avg(Budget) is 230000.00
decimal avg = datastore.Avg<D_Department>(o => o.Budget);
Console.WriteLine(
"The average budget of all records Avg(Budget) is: {0}",
avg);
/*This code produces the following output:
The average budget of all records Avg(Budget) is: 230000.0000
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x