1

如何从 WADLogsTable 中获取按日期排序的最后 100 条记录?

我试图用这段代码来做,但它不起作用

                var query = (from entity in tsc.CreateQuery<LogsObject>("WADLogsTable")
                        where entity.PartitionKey.CompareTo(startTime.ToUniversalTime().Ticks.ToString("D19")) >= 0
                        orderby entity.EventTickCount descending
                        select entity);

其中 tsc 是 TableServiceContext。

我可以获得记录,但我对最近的日志感兴趣。

谢谢,

4

2 回答 2

0

Windows Azure 表存储不支持排序,因此实体返回时总是按其 PartitionKey+RowKey 排序。但我怀疑日志条目已经按时间倒序排列。不是吗?

[编辑]显然他们不是。:-)

于 2012-06-03T18:47:56.570 回答
0
 CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ATCommon.DiagnosticConfig);
    CloudTableClient cloudTableClient = storageAccount.CreateCloudTableClient();
    TableServiceContext serviceContext = cloudTableClient.GetDataServiceContext();
    IQueryable<WadLogEntity> traceLogsTable = serviceContext.CreateQuery<WadLogEntity>("WADLogsTable");
    var selection = from row in traceLogsTable where row.PartitionKey.CompareTo("0" + DateTime.UtcNow.AddHours(hours).Ticks) >= 0 select row;
    //var selection = from row in traceLogsTable where row.PartitionKey.CompareTo("0" + DateTime.UtcNow.AddMinutes(-5.0).Ticks) >= 0 select row;
    CloudTableQuery<WadLogEntity> query = selection.AsTableServiceQuery<WadLogEntity>();
    IEnumerable<WadLogEntity> output = query.Execute();
 return output.OrderByDescending(s => s.Timestamp).Take(100).ToList();
于 2016-03-01T12:17:38.490 回答