【问题标题】:cannot convert to microsoft.azure.cosmosDB.table.itableentity无法转换为 microsoft.azure.cosmosDB.table.itableentity
【发布时间】:2018-08-03 15:19:57
【问题描述】:

我正在尝试使用存储连接字符串将一些测试值插入到 Azure 表中。当我尝试执行插入操作时,它显示错误,因为无法将 TableStorage.RunnerInputs 转换为 Microsoft.azure.cosmosDB.table.itableentity。 我正在参考https://docs.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);

跑步者类

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

    }
}

错误截图供参考。谁能让我知道我们该如何克服这个问题?已经尝试通过强制转换值,但结果是一样的。

【问题讨论】:

    标签: c# .net azure azure-web-app-service azure-storage


    【解决方案1】:

    谁能告诉我如何克服这个问题?

    您的问题似乎是 TableEntity 包引用无法与 TableOperation 包引用匹配。 Azure COMOS DB 和 Azure 表存储是不同的表。他们的软件包不能相互配合。您可以对这些类使用相同的包参考来解决您的问题(例如“Microsoft.WindowsAzure.Storage.Table”)。
    结果是这样的:

    【讨论】:

    • 连接字符串作为键/值存储在 app.config 文件中。键是连接字符串的名称,例如'StorageConnectionString'。值为Azure存储账户中Access Key的连接字符串(此链接:stackoverflow.com/questions/6985921/…)。
    猜你喜欢
    • 1970-01-01
    • 2023-02-02
    • 2016-06-30
    • 2016-01-14
    • 2013-07-25
    • 2016-07-05
    • 2017-01-24
    • 2016-01-07
    • 2015-07-16
    相关资源
    最近更新 更多