2015-11-11 63 views
0

我想要查询对该表进行的最新插入,Azure移动服务默认添加__createdAt列。查询Azure移动服务中的最新条目

因此,我打算根据该特定列对表进行排序,因为__createdAt是系统属性。我想把它添加到我的表格模型中。

现在我的问题是:如何在C#中查询此?

回答

1

您可以根据那些在你的模型跟踪__createdAt列的属性,以及排序:

public class Person { 
    public string Id { get; set; } 
    public string Name { get; set; } 
    public int Age { get; set; } 
    [CreatedAt] public DateTime CreatedAt; 
} 

和代码:

var table = MobileService.GetTable<Person>(); 
var lastItems = await table 
    .OrderByDescendent(p => p.CreatedAt) 
    .Take(1) 
    .ToEnumerableAsync(); 
var lastItem = lastItems.FirstOrDefault(); 
+0

真棒。谢谢。 – Kinani