cannot convert to microsoft.azure.cosmosDB.table.itableentity

拥有回忆 提交于 2020-03-03 08:07:28

问题


I'm trying to insert some test values into an Azure table using storage connection string. When I tried to perform insert operation it showing error as cannot convert TableStorage.RunnerInputs to Microsoft.azure.cosmosDB.table.itableentity. I'm working on this with the reference to 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);

Runner class

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

    }
}

Error Screenshot for reference. Can anyone let me know how can we overcome this? Have tried by casting the value, but the result is same.


回答1:


Can anyone let me know how can we overcome this?

It seems that your problem is TableEntity package reference can not be matched with TableOperation package reference. The Azure Comos DB and Azure Table Storage are different tables. Their packages don't work with each other. You could use the same package reference for these classes to solve your problem( like 'Microsoft.WindowsAzure.Storage.Table').
The result is like this:



来源:https://stackoverflow.com/questions/48950037/cannot-convert-to-microsoft-azure-cosmosdb-table-itableentity

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