Reference > Functions > Mathematical

Log

  • 2005, 2008
  • 2012, 2014, 2016, 2017, 2019, 2022

Log (Logarithm) Mathematical Function

Use the Log function to return the natural logarithm of the specified expression.

Syntax

db.fx.Log({expression})

Arguments

expression
The value to use in the logarithm calculation.

Returns

float

Examples

Select Statement

Select the natural logarithm of a product's weight (which is nullable in the database).

float? result = db.SelectOne(
        db.fx.Log(dbo.Product.Weight)
    )
    .From(dbo.Product)
    .Execute();

Where Clause

Select the natural logarithm of a product's depth (which is nullable in the database).

float? result = db.SelectOne(
        db.fx.Log(dbo.Product.Depth)
    )
    .From(dbo.Product)
    .Execute();

Order By Clause

Select and order by the natural logarithm of a product's depth.

IEnumerable<Product> result = db.SelectMany<Product>()
    .From(dbo.Product)
    .OrderBy(db.fx.Log(dbo.Product.Depth).Desc())
    .Execute();

Group By Clause

Select product details grouped by product category and the natural logarithm of the product's depth.

IEnumerable<dynamic> results = db.SelectMany(
        dbo.Product.ProductCategoryType,
        db.fx.Log(dbo.Product.Depth).As("calculated_value")
    )
    .From(dbo.Product)
    .GroupBy(
        dbo.Product.ProductCategoryType,
        db.fx.Log(dbo.Product.Depth)
    )
    .Execute();

Having Clause

Select the ids of all products, grouped by product category type having a natural logarithm of the product's height greater than the product's width.

IEnumerable<ProductCategoryType?> results = db.SelectMany(
        dbo.Product.ProductCategoryType
    )
    .From(dbo.Product)
    .GroupBy(
        dbo.Product.ProductCategoryType,
        db.fx.Log(dbo.Product.Height),
        dbo.Product.Width
    )
    .Having(
        db.fx.Log(dbo.Product.Height) > dbo.Product.Width
    )
    .Execute();
Previous
Floor

© 2024 dbExpression. All rights reserved.