我想订购我保存在SQLite数据库中的日历条目,以在Listview中显示它们。如何使用SQLite-net-plc订购它们?
我以为我可以写:.OrderBy<CalendarEntryStartDate>
,但是它不起作用,我尝试使用SQLite命令,但是由于m.db的困扰,我在使用它们时遇到了一些麻烦。
using System;
using SQLite;
namespace Stundenplan.Models
{
public class CalendarEntry
{
[PrimaryKey, AutoIncrement]
public int CalendarEntryId { get; set; }
public string CalendarEntryTitle { get; set; }
public string CalendarEntryDescription { get; set; }
[Column("StatDate")]
public DateTime CalendarEntryStartDate { get; set; }
public DateTime CalendarEntryEndDate { get; set; }
public TimeSpan CalendarEntrySpan { get; set; }
public string CalendarEntryParticipants { get; set; }
public string CalendarEntrytLocation { get; set; }
public Boolean CalendarEntryPrivate { get; set; }
public string CalendarEntryTags { get; set; }
public string CalendarEntryColorTag { get; set; }
}
}
using SQLite;
using System.Collections.Generic;
using Stundenplan.Models;
using System.Threading.Tasks;
namespace Stundenplan.Data
{
public class CalendarEntryDatabase
{
readonly SQLiteAsyncConnection calendarentrydatabase;
public CalendarEntryDatabase(string dbPath)
{
calendarentrydatabase = new SQLiteAsyncConnection(dbPath);
calendarentrydatabase.CreateTableAsync<CalendarEntry>().Wait();
}
public Task<List<CalendarEntry>> GetCalendarEntrysAsync()
{
return calendarentrydatabase.Table<CalendarEntry>().ToListAsync();
}
public Task<CalendarEntry> GetCalendarEntryAsync(int id)
{
return calendarentrydatabase.Table<CalendarEntry>().Where(i => i.CalendarEntryId == id).FirstOrDefaultAsync();
}
public Task<int> SaveCalendarEntryAsync(CalendarEntry calendarentry)
{
if (calendarentry.CalendarEntryId == 0)
{
return calendarentrydatabase.InsertAsync(calendarentry);
}
else
{
return calendarentrydatabase.UpdateAsync(calendarentry);
}
}
public Task<int> DeleteCalendarEntryAsync(CalendarEntry calendarentry)
{
return calendarentrydatabase.DeleteAsync(calendarentry);
}
public Task<List<CalendarEntry>> GetCalendarEntriesOrderedByStartDateAsync()
{
return calendarentrydatabase.Table<CalendarEntry>().OrderBy<>;
}
}
}
我得到了错误
CS0103:名称“ CalendarEntryStartDate”在当前上下文中不存在;
和
CS0305:方法组“ OrderBy”(通用)的用法需要1-Typeargumetns。
我在做什么错了?
答案 0 :(得分:2)
OrderBy
需要一个lambda
表达式作为参数
OrderBy(x => x.CalendarEntryStartDate)