开发者

WP7 Sterling Database DateTime Index

开发者 https://www.devze.com 2023-03-29 03:02 出处:网络
开发者_JAVA技巧I am using a Sterling Database and have defined a class and index as follows public class SingleEventDB :TimetableEventDB
开发者_JAVA技巧

I am using a Sterling Database and have defined a class and index as follows

public class SingleEventDB :TimetableEventDB
{
    public DateTime EventDateTime { get; set; }
}

CreateTableDefinition<SingleEventDB, string>(k => k.UniqueId)
    .WithIndex<SingleEventDB,DateTime,string>("BYDATETIME",i=>i.EventDateTime)

I access this like this

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;
}

However whilst the where clause is correctly filtering out the objects which are earlier than the input date, they are returned in the order that they were created, rather than in the index (DateTime) order.

Is this expected, or am I doing something wrong.

And is there a way to insert an orderby clause in t.


Seems you missed the Enumerable.ToList extension method! And yes, you could simply add orderby eveItemDB.Index to your code, like this:

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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消