Average Operator in Linq to Entity 4 With Examples



Average operator in Linq to Entity Framework 4 with examples

  1. In this article i will explain the use of average operator in linq to entity framework 4.0
  2. The Average operator returns the average of the numeric values that exists in the elements of an input sequence.
  3. One variation of the Average operator enumerates the input source sequence of Numeric type elements by creating an average of the elements. 
  4. The second variation enumerates the source input sequence and determines the average for the member that is returned by a selector for every element in the input source sequence.
  5. You can use the second syntax for the Average operator to define a query in which the average is just one of the results that needs to be extracted
  6. The following code examples illustrate the usage of the Average operator.

C#


var expr =   (from p in products    
              select p.Price    ).Average()
var expr =  (from p in products      
            select new { p.Price }    ).Average(Function(p) p.Price)
VB


Dim expr =   (from p in products    
              select p.Price    ).Average()
Dim expr =  (from p in products      
            select new { p.Price }    ).Average(Function(p) p.Price)


The above example clearly shows the use of average operator in linq to entityframework 4.0

0 comments:

Post a Comment