UserDefinedFunctionProperties Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應