0

Getting an error while trying to get the entities from Azure Table on basis of Timestamp which is of type Edm.DateTime:

StorageError: A binary operator with incompatible types was detected. Found operand types 'Edm.DateTime' and 'Edm.String' for operator kind 'GreaterThanOrEqual'

enter image description here Code:

let res: IQueryPrePostAuthResponse[] = [];
let query = new TableQuery();
query = query.where('PartitionKey eq ?', searchQuery.user_id);

const entGen = TableUtilities.entityGenerator;
const dateFrom = entGen.DateTime(new Date(searchQuery.date_from));
const dateTo = entGen.DateTime(new Date(searchQuery.date_to));
query = query.and(
 'Timestamp >= ? and Timestamp <= ?',
  dateFrom,
  dateTo,
);

As in code both variables(dateFrom, & dateTo) are of DateTime type and Timestamp is of DateTime type. According to Odata Docs link query comparison operator, The data types on both sides of a comparison operator must be compatible. Here is my case both are the same, been then I am getting an error.

4

1 回答 1

0

当我在将它发送到查询之前打印dateTodateFrom时。

const entGen = TableUtilities.entityGenerator;
const dateFrom = entGen.DateTime(new Date(searchQuery.date_from));
const dateTo = entGen.DateTime(new Date(searchQuery.date_to));
console.log(dateFrom);
console.log(dateTo);

我在输出中得到了这个:- 在此处输入图像描述 经过大量调试后,我知道我发送dateFromdateTo的方式不正确。
正确的方法是dateFrom._dateTo._。但这应该在 Azure Table 或 OData Query 中提及,但那里没有。

根据 Odata Docs链接查询比较运算符,比较运算符两侧的数据类型必须兼容

这会造成混乱,因为即使两者的类型相同也会出错。正确的代码如下:-

let res: IQueryPrePostAuthResponse[] = [];
let query = new TableQuery();
query = query.where('PartitionKey eq ?', searchQuery.user_id);

const entGen = TableUtilities.entityGenerator;
const dateFrom = entGen.DateTime(new Date(searchQuery.date_from));
const dateTo = entGen.DateTime(new Date(searchQuery.date_to));
query = query.and(
 'Timestamp >= ? and Timestamp <= ?',
  dateFrom._,
  dateTo._,
);

现在我可以根据Timestamp属性从 Azure 表中查询实体。 在此处输入图像描述

于 2021-05-27T13:08:15.653 回答