Try .NET /elinq/
Powered by Try .NET

SQL Server Aggregate Functions

AVG example with ROUND

public static readonly DataType<decimal> USD = DataTypes.DECIMAL.Numeric(10, 2);

public void CalcAveragePrice()
{

    var avgProductPrice = DbContext.Set<Scalar<decimal>>()
        .Query((Products products, Scalar<decimal> alias) =>
        {
            var result = SELECT<Scalar<decimal>>(USD.Cast(ROUND(AVG(products.ListPrice), 2)).@as(alias.Value));
            FROM(products);

            return result;
        })
        .Single();

    Console.WriteLine(avgProductPrice.Value);
}

ELINQ features a statically typed dynamic type system. Users can derive from basic types and specify precision, scale, length, etc. Then the produced type can be used for literals and CAST (run and see generated SQL).


< BACK | HOME