无法转换为 microsoft.azure.cosmosDB.table.itableentity

sai*_*mar 1 .net c# azure azure-storage azure-web-app-service

我正在尝试使用存储连接字符串将一些测试值插入到 Azure 表中。当我尝试执行插入操作时,它显示错误,因为无法将 TableStorage.RunnerInputs 转换为 Microsoft.azure.cosmosDB.table.itableentity。我正在参考https://learn.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-dotnet来解决这个问题

*


        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
 CloudConfigurationManager.GetSetting("StorageConnectionString"));

        //Create the table client.
               CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

        //Create the CloudTable object that represents the "people" table.
       CloudTable table = tableClient.GetTableReference("InputParameters");

        table.CreateIfNotExists();

        //Create a new customer entity.
       RunnerInputs RunnerInput = new RunnerInputs("OnlyDate", "rowkey");

        //CloudTable test = null;


        RunnerInput.InputDate = "20180213";


        //Inputvalue = "20180213";
        //Create the TableOperation object that inserts the customer entity.
               TableOperation insertOperation = TableOperation.Insert(RunnerInput);

        //Execute the insert operation.
               table.Execute(insertOperation);
Run Code Online (Sandbox Code Playgroud)

跑者级别

namespace TableStorage
{
 public  class RunnerInputs:TableEntity
    {
        public RunnerInputs(string ParameterName,string RowValue)
        {
            this.PartitionKey = ParameterName;
            this.RowKey = RowValue;
        }
        public string InputDate { get; set; }

    }
}
Run Code Online (Sandbox Code Playgroud)

错误截图供参考。谁能告诉我我们怎样才能克服这个问题?已尝试通过转换值,但结果是相同的。

错误图片供参考

Jan*_*ang 5

谁能告诉我我们怎样才能克服这个问题?

看来您的问题是TableEntity包引用无法与 TableOperation包引用匹配。Azure COMOS DB 和 Azure 表存储是不同的表。他们的软件包不能相互兼容。您可以对这些类使用相同的包引用来解决您的问题(例如“Microsoft.WindowsAzure.Storage.Table”)。
结果是这样的: 在此输入图像描述