query rowkey with greater than in azure table storage

若如初见. 提交于 2019-12-24 13:03:15

问题


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();
    }
}

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();

but I get a 404. Any ideas?


回答1:


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.

The linq query which should work is:

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


来源:https://stackoverflow.com/questions/35628273/query-rowkey-with-greater-than-in-azure-table-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!