简体   繁体   English

Azure表存储:将C#转换为NodeJS-如何使用CompareTo?

[英]Azure Table Storage: Translate C# to NodeJS - How to use CompareTo?

There are a lot of examples circulating around the internet about how you can use CompareTo with Azure Table Storage to basically do some substring searching from C# , but I can't find anything showing how to do it in NodeJS and all the syntaxes I've tried to put together just throw back various syntax or invalid query storage exceptions. 互联网上有很多例子,涉及如何使用CompareTo和Azure Table Storage基本上从C#进行一些子字符串搜索,但是我找不到任何显示如何在NodeJS和我使用的所有语法中进行显示的子字符串。试图将各种语法或无效的查询存储异常放在一起。

Can anyone tell me how to do the equivalent of the C# example on this website, but from NodeJS? 有人可以告诉我如何通过NodeJS等效于本网站上的C#示例吗? https://lifeportal.azurewebsites.net/azure-table-storage-searching-entities-using-query-like-substring-or-left/ https://lifeportal.azurewebsites.net/azure-table-storage-searching-entities-using-query-like-substring-or-left/

string projectIdString = projectId.ToString().ToLower(); // projectId - Guid
string startQuery = projectIdString + "_"; // Our separate symbol
string endQuery = projectIdString + "`"; // Next symbol in ASCII table after "_"

Expression<Func<DynamicTableEntity, bool>> filters = (e.RowKey.CompareTo(startQuery) >= 0 && e.RowKey.CompareTo(endQuery) < 0);
CloudTable table = _storageContext.Table(Tables.Users);

bool result = await DeleteAllEntitiesInBatches(table, filters);
return result;

What seems like the most obvious of: 似乎最明显的是:

const TABLE_NAME = 'MYTABLE';

var azure = require('azure-storage');
var tableService = azure.createTableService();
var query = new azure.TableQuery()
    .where('PartitionKey eq ?', 'MYKEY').and('RowKey.compareTo(\'1-\') ge ?', 0);

tableService.queryEntities(TABLE_NAME, query, null, function(error, result, response) {
    if (!error) {
        // result.entries contains entities matching the query
    }
});

Results in: 结果是:

"An unknown function with name 'RowKey.compareTo' was found. This may also be a key lookup on a navigation property, which is not allowed."

It looks like you are attempting to query RowKey with a StartsWith . 似乎您正在尝试使用StartsWith查询RowKey。 In node.js you can use operator ge (greater than or equal) to do that. 在node.js中,您可以使用运算符ge (大于或等于)来执行此操作。

So your code would be something like: 因此,您的代码将类似于:

var query = new azure.TableQuery()
    .where('PartitionKey eq ?', 'MYKEY').and('RowKey ge ?', '<starts with substring>');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM