gpt4 book ai didi

c# - Azure 中的时间戳查询

转载 作者:行者123 更新时间:2023-12-02 01:55:09 25 4
gpt4 key购买 nike

我真的陷入了 Azure 表存储上的查询过滤器困境。请问如何用时间戳查询?当我单独查询分区键 1005 时,我得到了我不想要的完整表。当我添加带有时间戳的“and”条件时(尝试了多种格式,但它没有返回任何内容。下面的代码片段:

var lowerlimit = DateTime.Today.AddDays(-52).ToString("yyyy-MM-dd");

string dateRangeFilter = TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "1005"),
TableOperators.And,
TableQuery.GenerateFilterCondition("TimeStamp", QueryComparisons.GreaterThanOrEqual, lowerlimit));

最佳答案

我可以将时间戳与 Microsoft.WindowsAzure.Storage 版本 4.0.1.0 一起使用。只是举例

var query = TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("Level", QueryComparisons.Equal, "ERROR"),
TableOperators.And,
TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThanOrEqual, DateTimeOffset.Now.AddDays(-20).Date));

var query2 = TableQuery.CombineFilters(query,
TableOperators.And,
TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.LessThanOrEqual, DateTimeOffset.Now));

var exQuery = new TableQuery<LogEntry>().Where(query2);

CloudTableClient tableClient = _storageAccount.CreateCloudTableClient();

CloudTable table = tableClient.GetTableReference(_tableName);
var results = table.ExecuteQuery(exQuery).Select(ent => (T) ent).ToList();

关于c# - Azure 中的时间戳查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17325445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com