Skip to content

Commit ea10b11

Browse files
authored
Merge pull request #180203 from Venkat1340/users/Venkat1340/1516301-Azurefunctionreference
Fix task id 1516301 Update C# SDK Azure Functions.
2 parents dbfeedd + 0542380 commit ea10b11

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

articles/azure-functions/manage-connections.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,48 +81,43 @@ http.request(options, onResponseCallback);
8181

8282
# [C#](#tab/csharp)
8383

84-
[DocumentClient](/dotnet/api/microsoft.azure.documents.client.documentclient) connects to an Azure Cosmos DB instance. The Azure Cosmos DB documentation recommends that you [use a singleton Azure Cosmos DB client for the lifetime of your application](../cosmos-db/performance-tips.md#sdk-usage). The following example shows one pattern for doing that in a function:
84+
[CosmosClient](/dotnet/api/microsoft.azure.cosmos.cosmosclient) connects to an Azure Cosmos DB instance. The Azure Cosmos DB documentation recommends that you [use a singleton Azure Cosmos DB client for the lifetime of your application](../cosmos-db/performance-tips-dotnet-sdk-v3-sql.md#sdk-usage). The following example shows one pattern for doing that in a function:
8585

8686
```cs
87-
#r "Microsoft.Azure.Documents.Client"
88-
using Microsoft.Azure.Documents.Client;
87+
#r "Microsoft.Azure.Cosmos"
88+
using Microsoft.Azure.Cosmos;
8989

90-
private static Lazy<DocumentClient> lazyClient = new Lazy<DocumentClient>(InitializeDocumentClient);
91-
private static DocumentClient documentClient => lazyClient.Value;
90+
private static Lazy<CosmosClient> lazyClient = new Lazy<CosmosClient>(InitializeCosmosClient);
91+
private static CosmosClient cosmosClient => lazyClient.Value;
9292

93-
private static DocumentClient InitializeDocumentClient()
93+
private static CosmosClient InitializeCosmosClient()
9494
{
9595
// Perform any initialization here
96-
var uri = new Uri("example");
96+
var uri = "https://youraccount.documents.azure.com:443";
9797
var authKey = "authKey";
98-
99-
return new DocumentClient(uri, authKey);
98+
99+
return new CosmosClient(uri, authKey);
100100
}
101101

102102
public static async Task Run(string input)
103103
{
104-
Uri collectionUri = UriFactory.CreateDocumentCollectionUri("database", "collection");
105-
object document = new { Data = "example" };
106-
await documentClient.UpsertDocumentAsync(collectionUri, document);
107-
104+
Container container = cosmosClient.GetContainer("database", "collection");
105+
MyItem item = new MyItem{ id = "myId", partitionKey = "myPartitionKey", data = "example" };
106+
await container.UpsertItemAsync(document);
107+
108108
// Rest of function
109109
}
110110
```
111-
If you are working with functions v3.x, you need a reference to Microsoft.Azure.DocumentDB.Core. Add a reference in the code:
112-
113-
```cs
114-
#r "Microsoft.Azure.DocumentDB.Core"
115-
```
116111
Also, create a file named "function.proj" for your trigger and add the below content :
117112

118113
```cs
119114

120115
<Project Sdk="Microsoft.NET.Sdk">
121116
<PropertyGroup>
122-
<TargetFramework>netcoreapp3.0</TargetFramework>
117+
<TargetFramework>netcoreapp3.1</TargetFramework>
123118
</PropertyGroup>
124119
<ItemGroup>
125-
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.12.0" />
120+
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.23.0" />
126121
</ItemGroup>
127122
</Project>
128123

0 commit comments

Comments
 (0)