查询行键大于Azure表存储中的行键 [英] query rowkey with greater than in azure table storage

查看:152
本文介绍了查询行键大于Azure表存储中的行键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了此链接和引用的白皮书,使我可以对插入表存储中的数据进行排序.存储的实体"具有简化的模式":

I used this link and the quoted white paper to allow me to sort data inserted into table storage. The 'entities' stored have this simplified 'schema':

public class Bla : TableEntity
{
    public Bla(){}

    public Bla(string partitionKey)
    {
        PartitionKey = partitionKey;

        // rowkey + partition = guid/pk
        // used to order blas
        RowKey = (DateTime.UtcNow.Ticks - DateTime.MinValue.Ticks).ToString();
    }
}

我可以轻松获得按行键升序排序的页面"(最大页面大小为1000),就像这样:

I can easily get a 'page' (maximum page size 1000) sorted by the rowkey ascendingly like so:

var query =
(from s in _table.CreateQuery<Bla>()
where
s.PartitionKey == _partitionKey &&
string.Compare(s.RowKey, rowKeyToUse, StringComparison.Ordinal) > 0 
select s).AsTableQuery();

我有一个用例,其中我想选择行键大于长号的任何实体(行键只是刻度线-用字符串表示的长号).所以我尝试了这个:

I have this use case where I would like to select any entity where the rowkey is greater than a long (the rowkey is just ticks - a long expressed as string). So I tried this:

var query =
(from s in _table.CreateQuery<Bla>()
where
s.PartitionKey == _partitionKey &&
s.RowKey.CompareTo(635919954373048408) > 0 &&
string.Compare(s.RowKey, rowKeyToUse, StringComparison.Ordinal) > 0 
select s).AsTableQuery();

但是我得到404.有什么想法吗?

but I get a 404. Any ideas?

推荐答案

我认为查询的问题在于您正在相互比较不同的类型.即具有较长时间戳记的字符串rowkey.

I think the issue with your query was that you're comparing different types with each other. Namely the string rowkey with your long timestamp.

应该起作用的linq查询是:

The linq query which should work is:

from entry in table 
where entry.RowKey.CompareTo("635919954373048408") >= 0 
select entry

这篇关于查询行键大于Azure表存储中的行键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆