Share via


UserDefinedFunction Class

Definition

Represents a user defined function in the Azure Cosmos DB service.

public class UserDefinedFunction : Microsoft.Azure.Documents.Resource
type UserDefinedFunction = class
    inherit Resource
Public Class UserDefinedFunction
Inherits Resource
Inheritance
UserDefinedFunction

Examples

The following examples show how to register and use UDFs.

await client.CreateUserDefinedFunctionAsync(collectionLink, new UserDefinedFunction { Id = "calculateTax", Body = @"function(amt) { return amt * 0.05; }" });
client.CreateDocumentQuery<Book>(collectionLink, "SELECT VALUE udf.calculateTax(b.price) FROM books b");
client.CreateDocumentQuery<Book>(collectionLink, new SqlQuerySpec("SELECT VALUE udf.calculateTax(b.price) FROM books b"));
client.CreateDocumentQuery<Book>(collectionLink).Select(b => UserDefinedFunctionProvider.Invoke("calculateTax", b.Price));

await client.CreateUserDefinedFunctionAsync(collectionLink, new UserDefinedFunction { Id = "toLowerCase", Body = @"function(s) { return s.ToLowerCase(); }" });
client.CreateDocumentQuery<Book>(collectionLink, "SELECT * FROM books b WHERE b.toLowerCase = 'war and peace'");
client.CreateDocumentQuery<Book>(collectionLink, new SqlQuerySpec(
    "SELECT * FROM books b WHERE b.toLowerCase = @bookNameLowerCase",
    new SqlParameterCollection(new SqlParameter[] {new SqlParameter { Name = "@bookNameLowerCase", Value = "War And Peace".ToLower()
 }})));
 client.CreateDocumentQuery<Book>(collectionLink).Where(b => UserDefinedFunctionProvider.Invoke("toLowerCase", b.Title) == "war and peace");

Remarks

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

Constructors

UserDefinedFunction()

Initializes a new instance of the UserDefinedFunction class for the Azure Cosmos DB service.

Properties

AltLink

Gets the alt-link associated with the resource from the Azure Cosmos DB service.

(Inherited from Resource)
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.

(Inherited from Resource)
Id

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

(Inherited from Resource)
ResourceId

Gets or sets the Resource Id associated with the resource in the Azure Cosmos DB service.

(Inherited from Resource)
SelfLink

Gets the self-link associated with the resource from the Azure Cosmos DB service.

(Inherited from Resource)
Timestamp

Gets the last modified timestamp associated with the resource from the Azure Cosmos DB service.

(Inherited from Resource)

Methods

GetPropertyValue<T>(String)

Gets property value associated with the specified property name from the Azure Cosmos DB service.

(Inherited from Resource)
LoadFrom(JsonReader, JsonSerializerSettings)

Loads the object from the specified JSON reader in the Azure Cosmos DB service.

(Inherited from JsonSerializable)
LoadFrom(JsonReader)

Loads the object from the specified JSON reader in the Azure Cosmos DB service.

(Inherited from JsonSerializable)
SaveTo(Stream, SerializationFormattingPolicy, JsonSerializerSettings)

Saves the object to the specified stream in the Azure Cosmos DB service.

(Inherited from JsonSerializable)
SaveTo(Stream, SerializationFormattingPolicy)

Saves the object to the specified stream in the Azure Cosmos DB service.

(Inherited from JsonSerializable)
SetPropertyValue(String, Object)

Sets property value associated with the specified property name in the Azure Cosmos DB service.

(Inherited from Resource)
ToByteArray()

Serialize to a byte array via SaveTo for the Azure Cosmos DB service.

(Inherited from Resource)
ToString()

Returns the string representation of the object in the Azure Cosmos DB service.

(Inherited from JsonSerializable)

Applies to