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();
}
精彩评论