1

我正在尝试创建一个简单的 DocumentDb hello world 程序并得到type or namespace name 'Azure' does not exist in namespace 'Microsoft'

using Microsoft.Azure

我通过 Nuget 添加了 DocumentDb 库。添加nuget包后是否需要手动添加对它的引用?我认为使用 nuget 会自动添加项目引用。

4

1 回答 1

0

根据您的另一个SO 线程,您似乎使用的是.net 项目而不是.net 核心项目。

.NET Framework 提供了一个全面的编程模型,用于在 Windows 上构建各种应用程序,从移动到 Web 再到桌面。

请尝试创建一个 .net 核心项目。我们可以从 nuget获取Microsoft.Azure.DocumentDB.Core 。我测试使用.net 核心项目在 Windows 平台上创建文档。它在我这边正常工作。我认为它也应该在 Mac 上运行。以下是我的演示代码。

 var endpointUrl = "https://documentdbnamespace.documents.azure.com:443/";
 var authorizationKey = "xxxxxxxxxx";
 var databaseId = "database";
 var collectionId = "collection"; //I use an existing collect


 using (_client = new DocumentClient(new Uri(endpointUrl), authorizationKey))
    {
       var collectionLink = UriFactory.CreateDocumentCollectionUri(databaseId, collectionId);
       var product = new Product
          {
             Id= Guid.NewGuid().ToString(),
             ProductId = "test"
          };
       Document created =  _client.CreateDocumentAsync(collectionLink, product).Result;
     }

Product.cs 类:

 public class Product
    {
        [JsonProperty(PropertyName = "id")]
        public string Id { get; set; }

        // used to set expiration policy
        [JsonProperty(PropertyName = "ttl", NullValueHandling = NullValueHandling.Ignore)]
        public int? TimeToLive { get; set; }

        public string ProductId { get; set; }
        public DateTime DateStarted { get; set; }
    }

在此处输入图像描述

我们还可以从文档中获得更多的文档示例代码。

于 2017-06-05T02:22:06.660 回答