Reference > Functions > Mathematical
Cos
- 2005
- 2008
- 2012
- 2014
- 2016
- 2017
- 2019
- 2022
- 2005, 2008, 2012, 2014, 2016, 2017, 2019, 2022
Cos (Cosine) Mathematical Function
Use the Cos
function to return the cosine of the specified expression.
Syntax
db.fx.Cos({expression})
Arguments
- expression
- – The value to use in the cosine calculation.
Returns
float
Examples
Select Statement
Select the cosine of a product's weight (which is nullable in the database).
float? result = db.SelectOne(
db.fx.Cos(dbo.Product.Weight)
)
.From(dbo.Product)
.Execute();
Where Clause
Select the cosine of a product's depth (which is nullable in the database).
float? result = db.SelectOne(
db.fx.Cos(dbo.Product.Depth)
)
.From(dbo.Product)
.Execute();
Order By Clause
Select and order by the cosine of a product's depth.
IEnumerable<Product> result = db.SelectMany<Product>()
.From(dbo.Product)
.OrderBy(db.fx.Cos(dbo.Product.Depth).Desc())
.Execute();
Group By Clause
Select product details grouped by product category and the cosine of the product's depth.
IEnumerable<dynamic> results = db.SelectMany(
dbo.Product.ProductCategoryType,
db.fx.Cos(dbo.Product.Depth).As("calculated_value")
)
.From(dbo.Product)
.GroupBy(
dbo.Product.ProductCategoryType,
db.fx.Cos(dbo.Product.Depth)
)
.Execute();
Having Clause
Select the ids of all products, grouped by product category type having a cosine 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.Cos(dbo.Product.Height),
dbo.Product.Width
)
.Having(
db.fx.Cos(dbo.Product.Height) > dbo.Product.Width
)
.Execute();