c# - 如何通过 SQLite-net-plc 在 Xamarin.Forms 中使用“.OrderBy”?
问题描述
我想订购我保存在 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。
我究竟做错了什么?
解决方案
OrderBy
期望lambda
表达式作为参数
OrderBy(x => x.CalendarEntryStartDate)
推荐阅读
- ivy - Ubuntu 安装 pylucene-6.5.0 ,常春藤错误
- c++ - 通过分支预测或缓存提升性能?
- c# - 单元测试 rabbitMQ c# Moq
- java - 通过在多个线程中调用方法对 java 方法进行单元测试
- python - Keras 模型:TypeError:无法腌制 _thread.lock 对象
- symfony - 迁移到 Symfony 3.4 后的 Autowire 服务错误 - 如何显式配置值?
- npm - 无法使用 yarn 安装最新版本的私有 npm 包
- javascript - 谷歌脚本拒绝插入谷歌链接作为链接@谷歌文档
- .net - vb.net 如何删除这个脚本标签?
- c++ - 如果不需要动态多态,基类是否应该声明虚拟方法?