Share via


UserDefinedFunctionProperties Class

Definition

Represents a user defined function in the Azure Cosmos service.

[System.Text.Json.Serialization.JsonConverter(typeof(Azure.Cosmos.TextJsonUserDefinedFunctionPropertiesConverter))]
public class UserDefinedFunctionProperties
[<System.Text.Json.Serialization.JsonConverter(typeof(Azure.Cosmos.TextJsonUserDefinedFunctionPropertiesConverter))>]
type UserDefinedFunctionProperties = class
Public Class UserDefinedFunctionProperties
Inheritance
UserDefinedFunctionProperties
Attributes

Examples

The following examples show how to register and use UDFs.

await this.container.UserDefinedFunctions.CreateUserDefinedFunctionAsync(
    new UserDefinedFunctionProperties 
    { 
        Id = "calculateTax", 
        Body = @"function(amt) { return amt * 0.05; }" 
    });

QueryDefinition sqlQuery = new QueryDefinition(
    "SELECT VALUE udf.calculateTax(t.cost) FROM toDoActivity t where t.cost > @expensive and t.status = @status")
    .WithParameter("@expensive", 9000)
    .WithParameter("@status", "Done");

await foreach(double tax = this.container.Items.GetItemsQueryIterator<double>(
    sqlQueryDefinition: sqlQuery,
    partitionKey: "Done")
{
    Console.WriteLine(tax);
}

Remarks

Azure Cosmos supports JavaScript user defined functions (UDFs) which are stored in the database and can be used inside queries. Refer to https://docs.microsoft.com/azure/cosmos-db/sql-api-sql-query#javascript-integration for how to use UDFs within queries. Refer to https://docs.microsoft.com/azure/cosmos-db/programming#udf for more details about implementing UDFs in JavaScript.

Constructors

UserDefinedFunctionProperties()

Properties

Body

Gets or sets the body of the user defined function for the Azure Cosmos DB service.

ETag

Gets the entity tag associated with the resource from the Azure Cosmos DB service.

Id

Gets or sets the Id of the resource in the Azure Cosmos DB service.

Applies to