Could not load file or assembly 'Microsoft.Azure.Documents.Client - Azure-Table-Api

落爺英雄遲暮 提交于 2019-12-06 01:38:21

As I have tested, I think you should uninstall all your package about Microsoft.Azure.CosmosDB.Table.

Change to use WindowsAzure.Storage package to add entity in table.

Also, you need to set the partition key and row key. The following code defines an entity class that uses the customer's first name as the row key and last name as the partition key.

An entity's partition and row key uniquely identify it in the table. Entities with the same partition key can be queried faster than entities with different partition keys, but using diverse partition keys allows for greater scalability of parallel operations.

You could refer to the following code:

In Program:

public static void  Main(string[] args)
        {
            method().Wait();
        }
        static private async Task method()
        {
            var connectionString = "DefaultEndpointsProtocol=https;AccountName=accountname;AccountKey=xFWWad+YMoW/R7P54ppqGMDs7obGYj3ciEjokt+nkomwYfOh6mUcmcvJLV/puGistsKuGCfOwreCfptK1AwAAQ==;EndpointSuffix=core.windows.net";

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            CloudTable table = tableClient.GetTableReference("table1");

            Person customer1 = new Person("Harp", "Walter");
            customer1.Firstname = "Walter@contoso.com";
            TableOperation insertOperation = TableOperation.Insert(customer1);

            await table.ExecuteAsync(insertOperation);
        }
        class Person : TableEntity
        {
            public Person(string lastName, string firstName)
            {
                this.PartitionKey = lastName;
                this.RowKey = firstName;
            }

            public Person() { }

            public string Firstname { get; set; }
        }

In csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="WindowsAzure.Storage" Version="9.1.1" />
  </ItemGroup>

</Project>

Replace Microsoft.Azure.CosmosDB.Table package with Microsoft.Azure.Cosmos.Table. Replace Microsoft.Azure.CosmosDB.Table namespace with Microsoft.Azure.Cosmos.Table.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!