Table of Contents

Class UserDefinedFunctionProvider

Namespace
Microsoft.Azure.Documents.Linq
Assembly
Microsoft.Azure.Documents.Client.dll

Helper class to invoke User Defined Functions via Linq queries in the Azure Cosmos DB service.

public static class UserDefinedFunctionProvider
Inheritance
UserDefinedFunctionProvider
Inherited Members

Methods

Invoke(string, params object[])

Helper method to invoke User Defined Functions via Linq queries in the Azure Cosmos DB service.

public static object Invoke(string udfName, params object[] arguments)

Parameters

udfName string

the UserDefinedFunction name

arguments object[]

the arguments of the UserDefinedFunction

Returns

object

Examples

 await client.CreateUserDefinedFunctionAsync(collectionLink, new UserDefinedFunction { Id = "calculateTax", Body = @"function(amt) { return amt * 0.05; }" });
 var queryable = client.CreateDocumentQuery<Book>(collectionLink).Select(b => UserDefinedFunctionProvider.Invoke("calculateTax", b.Price));

// Equivalent to SELECT * FROM books b WHERE udf.toLowerCase(b.title) = 'war and peace'" 
await client.CreateUserDefinedFunctionAsync(collectionLink, new UserDefinedFunction { Id = "toLowerCase", Body = @"function(s) { return s.ToLowerCase(); }" });
queryable = client.CreateDocumentQuery<Book>(collectionLink).Where(b => UserDefinedFunctionProvider.Invoke("toLowerCase", b.Title) == "war and peace");

Remarks

This is a stub helper method for use within LINQ expressions. Cannot be called directly. Refer to http://azure.microsoft.com/documentation/articles/documentdb-sql-query/#linq-to-documentdb-sql for more details about the LINQ provider. Refer to http://azure.microsoft.com/documentation/articles/documentdb-sql-query/#javascript-integration for more details about user defined functions.

See Also