WP7 Sterling数据库日期时间索引

本文关键字:时间 索引 日期 数据库 Sterling WP7 | 更新日期: 2023-09-27 18:05:54

我正在使用Sterling数据库,并定义了一个类和索引如下

public class SingleEventDB :TimetableEventDB
{
    public DateTime EventDateTime { get; set; }
}
CreateTableDefinition<SingleEventDB, string>(k => k.UniqueId)
    .WithIndex<SingleEventDB,DateTime,string>("BYDATETIME",i=>i.EventDateTime)

我像这样访问

public List<SingleEvent> GetAllSingleEvents(DateTime StartDate)
{
    var allSingleEvents = new List<SingleEvent>();
    var result =
        from eveItemDB in App.MyDatabase.Query<SingleEventDB, DateTime, string>("BYDATETIME")
        where (eveItemDB.Index >= StartDate)
        select new SingleEvent
        {
            UniqueId = eveItemDB.LazyValue.Value.UniqueId,
            NextDateTime = eveItemDB.Index,
            Details = eveItemDB.LazyValue.Value.Details,
            Location = eveItemDB.LazyValue.Value.Location
        };
    foreach (SingleEvent eveItem in result)
    {
        allSingleEvents.Add(eveItem);
    }
    return allSingleEvents;
}

然而,尽管where子句正确地过滤掉了早于输入日期的对象,但它们是按照创建的顺序返回的,而不是按照索引(DateTime)的顺序。

这是预期的吗?还是我做错了什么?

是否有办法在t中插入顺序子句

WP7 Sterling数据库日期时间索引

似乎你错过了Enumerable。列表扩展方法!是的,您可以简单地将orderby eveItemDB.Index添加到您的代码中,像这样:

public List<SingleEvent> GetAllSingleEvents(DateTime StartDate)
{
    var result =
        from eveItemDB in App.MyDatabase.Query<SingleEventDB, DateTime, string>("BYDATETIME")
        where (eveItemDB.Index >= StartDate)
        orderby eveItemDB.Index
        select new SingleEvent
        {
            UniqueId = eveItemDB.LazyValue.Value.UniqueId,
            NextDateTime = eveItemDB.Index,
            Details = eveItemDB.LazyValue.Value.Details,
            Location = eveItemDB.LazyValue.Value.Location
        };
    return result.ToList();
}