问题
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