来自WadLogsTable的最后记录

时间:2012-06-03 17:43:57

标签: azure azure-storage

如何从日期订购的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。

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

谢谢,

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分: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();