简体   繁体   English

如何使用 C# 从 Azure 表存储中检索最新记录?

[英]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.我在存储表中有数十万条数据需要查询。

  1. First approach is to retrieve all the data and then queried as per the requirement but its taking too much time.第一种方法是检索所有数据,然后根据要求进行查询,但这需要太多时间。

  2. 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.

相关问题 如何在 Azure 表存储中使用 RowKey 或时间戳检索最新记录 - How to retrieve latest record using RowKey or Timestamp in Azure Table storage 如何使用 c# 从 azure blob 存储中检索 xml 文件 - how to retrieve an xml file from azure blob storage using c# Azure C# Function:如何从表存储中读取 - Azure C# Function: How to read from Table Storage 如何使用 C# 连接到 Azure 存储表 - How to connect to Azure Storage Table with C# 如何使用C#从Azure存储容器还原数据库 - How to restore database from azure storage container using c# 如何使用C#从Azure存储下载所有文件? - How to download all files from Azure Storage using C#? 在C#中使用LinQ将父表,子表和GrandChild表与孙表中的最新记录连接起来 - Join Parent, Child and GrandChild tables with latest record from grandchild table using LinQ in C# 如何使用 C# 中的 Azure.Storage.Blobs 以 ByteArray 格式从 Azure 存储 blob 中获取文件 - How to get file from Azure storage blob in a ByteArray format using Azure.Storage.Blobs in C# 如何使用 Blob 存储中的 Azure 函数和 C# 从 JSON 文件中获取数据以及将 JSON 数据存储为 Azure 表存储中的列 - How to get data from a JSON file using Azure functions and C# which is in Blob storage and Storing JSON data as columns in Azure table storage 如何在日期和时间之间从azure表存储中检索数据 - How to retrieve data from azure table storage between date and time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM