我正在尝试输出数据库中的所有信息。从我的代码,它的工作原理。但它实际上输出了一切。我想按日期订购。我怎样才能做到这一点。以下是我的代码:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (!App.ViewModel.IsDataLoaded)
{
App.ViewModel.LoadData();
}
using (DatabaseContext c = new DatabaseContext(DatabaseContext.ConnectionString))
{
//c.CreateIfNotExists();
if (!c.DatabaseExists())
{
c.CreateDatabase();
}
c.LogDebug = true;
//output todolist data from database
try
{
MLongListSelector.ItemsSource = c.ToDoList.ToList();
}
catch (Exception exc)
{
Console.WriteLine(exc.Source + ":" + exc.Message);
}
}
}
答案 0 :(得分:1)
var result = c.ToDoList.OrderBy(datefilter => datefilter.Date).ToList();
按今天的当前日期和时间排序,
DateTime today = DateTime.Today;
var result1 = c.ToDoList().Where(test => test.Date.Date == today).OrderByDescending(t=>t.Date).ToList();