Я могу вставить ключ строки и ключ раздела в хранилище таблиц Azure:
TableOperationinsertOperation = TableOperation.Insert(customer1); таблица.Выполнить(insertOperation); StoreKeyInQ(insertOperation);
// Create a new customer entity.
CustomerEntity customer1 = new CustomerEntity("URL", "Name"+Guid.NewGuid());
customer1.path = fullpath;
"CustomerEntity" выглядит следующим образом:
public class CustomerEntity : TableEntity
{
public CustomerEntity(string ID, string Name)
{
this.PartitionKey = ID;
this.RowKey = Name;
}
public CustomerEntity() { }
public string path { get; set; }
}
Я написал код для создания очереди, как показано ниже:
public void StoreKeyInQ(TableOperation insertOperation)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
//craete a queue client
CloudQueueClient cloudQueueClient = storageAccount.CreateCloudQueueClient();
//retrive a reference to a container
CloudQueue cloudQueue = cloudQueueClient.GetQueueReference("myqueue");
//create the queue if does not exists
cloudQueue.CreateIfNotExists();
// Create a message and add it to the queue.
CloudQueueMessage message = new CloudQueueMessage(insertOperation); //Here is the error as "CloudQueueMessage" can't take a argument type "TableOperation"
queue.AddMessage(message);
}
Как решить эту ошибку? Как передать ключ «rowkey» и «partition» хранилища таблицы в очередь?
EDIT:
Я добавил эти две строки для сериализации, это нормально?
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(customerEntity.GetType());
CloudQueueMessage message = new CloudQueueMessage(x.ToString());
Моя очередь выглядит так; однако не уверен, правильно это или нет? Кто-нибудь может пояснить - это правильно?
Customer
. По сути, вам нужно будет сериализовать свою модель как строку, а затем сохранить ее как сообщение. На принимающей стороне вы снова десериализуете его и получите объект, а оттуда вы сможете получить значенияPartitionKey
иRowKey
. - person Gaurav Mantri   schedule 09.05.2018