[英]How to retrieve latest record from Azure table storage using C#?
I'm facing an issue with azure table storage.我正面临 Azure 表存储问题。 I have hundreds of thousands of data into the storage table that I need to query.我在存储表中有数十万条数据需要查询。
First approach is to retrieve all the data and then queried as per the requirement but its taking too much time.第一种方法是检索所有数据,然后根据要求进行查询,但这需要太多时间。
Second approach is what if I get filtered data from table storage directly using query第二种方法是如果我直接使用查询从表存储中获取过滤数据会怎样
So as per my understanding second approach is best but I am not able to query appropriately.因此,根据我的理解,第二种方法是最好的,但我无法进行适当的查询。 How can I retrieve the last entry from Azure table storage, in this I am also trying to MAX and order by function but its not work for me.如何从 Azure 表存储中检索最后一个条目,在此我也尝试 MAX 并按功能排序,但它对我不起作用。
Not running code:不运行代码:
var query2 = new TableQuery().Where(
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, patientId.ToString()),
TableOperators.And,
TableQuery.GenerateFilterConditionForGuid("DeviceID", QueryComparisons.Equal, deviceId))
).OrderByDescending(x=>x.EventDate).Take(1).Select(x=>x.EventDate).ToList();
Running code which taking too much time:运行花费太多时间的代码:
var query = new TableQuery<TherapyEvent>().Where(
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, patientId.ToString()),
TableOperators.And,
TableQuery.GenerateFilterConditionForGuid("DeviceID", QueryComparisons.Equal, deviceId)) );
var resp= _table.ExecuteQuery(query).OrderByDescending(x=>x.EventDate).Take(1).Select(x=>x.EventDate).ToList()
As of now there is no direct way of fetching the latest record using the RowKey property.到目前为止,还没有使用 RowKey 属性获取最新记录的直接方法。 You may, however, shift the RowKey and list it in reverse chronological order and then fetch the top most entry which would be the latest.但是,您可以移动 RowKey 并按相反的时间顺序列出它,然后获取最上面的条目,即最新的条目。
You can check this blog for further details:您可以查看此博客以获取更多详细信息:
http://blog.smarx.com/posts/using-numbers-as-keys-in-windows-azure http://blog.smarx.com/posts/using-numbers-as-keys-in-windows-azure
Additional reference:补充参考:
How to retrieve latest record using RowKey or Timestamp in Azure Table storage 如何在 Azure 表存储中使用 RowKey 或时间戳检索最新记录
Note
: Using a string date time for the row key is not a good approach as Table Storage stores entities in ascending order based on the Row Key. Note
:使用字符串日期时间作为行键不是一个好方法,因为表存储根据行键以升序存储实体。
Hope it helps.希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.