检查 Azure Table 存储中是否存在实体

Checking if an entity exists in Azure Table Storage

我正在尝试通过 PartitionKey 和 RowKey 从 Azure Table 存储中检索实体。当我的 table 中确实有一个带有这些键的实体时,这非常有效。

tableService.retrieveEntity(tableName, partition, row, (err, res, resp) => {
    ...    
}

但是,当没有找到带有 for 键的实体时,我只是收到一个相当不清楚的错误 "One of the request inputs is not valid"...

Unhandled rejection StorageError: One of the request inputs is not valid.

有什么方法可以检查特定 Partition- 和 RowKey 的实体是否存在?

我尝试了您的代码来检索不存在的实体,然后出现以下错误:

{ ...
  name: 'StorageError',
  message: 'The specified resource does not exist.\nRequestId:c9f87517-0002-0028-5e32-660f88000000\nTime:2017-01-04T02:30:10.0502844Z',
  code: 'ResourceNotFound',
  statusCode: 404,
  requestId: 'c9f87517-0002-0028-5e32-660f88000000' }

当我插入日期错误的实体时,代码如下所示:

var task = {
  PartitionKey: {'_': 'hometasks'},
  RowKey: {'_': '1'},
  description: {'_': 'take out the trash'},
  dueDate: {'_': 'somethingwronghere', '$': 'Edm.DateTime'}
};

tableSvc.insertEntity('mytable',task, function (error, result, response) {
  console.log(error);
});

然后我得到和你一样的错误:

 { ...
  message: 'One of the request inputs is not valid.\nRequestId:2e8e6c07-0002-003a-7135-663b94000000\nTime:2017-01-04T02:49:02.8761981Z',
  code: 'InvalidInput',
  statusCode: 400,
  requestId: '2e8e6c07-0002-003a-7135-663b94000000' }

所以请仔细检查您是否收到了相应的错误消息。