C# SQLite需要SQL或Lambda指导
我一直在搜索SQLite查询示例。我在SQL中找到的那些方法不会编译,因为各种方法和类名都无法识别(即Open()、SQLiteDataReader和SQLiteDatabase) 我不太明白兰姆达的那些。例如,这:C# SQLite需要SQL或Lambda指导,c#,linq,sqlite,lambda,windows-store-apps,C#,Linq,Sqlite,Lambda,Windows Store Apps,我一直在搜索SQLite查询示例。我在SQL中找到的那些方法不会编译,因为各种方法和类名都无法识别(即Open()、SQLiteDataReader和SQLiteDatabase) 我不太明白兰姆达的那些。例如,这: public Task<List<Platypi>> GetAllLocationsAsync() { return new SQLiteAsyncConnection(SQLitePath).Table<Platypi>().ToLis
public Task<List<Platypi>> GetAllLocationsAsync()
{
return new SQLiteAsyncConnection(SQLitePath).Table<Platypi>().ToListAsync();
}
public任务GetAllLocationsAsync()
{
返回新的SQLiteAsyncConnection(SQLitePath).Table().ToListSync();
}
…可能通过返回的列表返回Platypi表中的每条记录。但我不想要全部,我想要限制/过滤记录;我想这是一个开始:
private async Task<List<Platypi>> GetLocationsForPeopleAndTimeRange(List<string> DuckbillIds, DateTime EarliestToShow, DateTime LatestToShow)
{
SQLiteAsyncConnection conn = new SQLiteAsyncConnection(SQLitePath);
var query = conn.Table<Locations>().Where(x => x.DuckbillId // ? what now ?
return await query.ToListAsync();
}
private async Task GetLocationsForPeopleAndTimeRange(列出DuckBillId、DateTime EarliestToShow、DateTime LatestToShow)
{
SQLiteAsyncConnection conn=新的SQLiteAsyncConnection(SQLitePath);
var query=conn.Table()。其中(x=>x.DuckbillId/?现在怎么办?
return wait query.ToListAsync();
}
…但我不知道如何构造Where()子句。我需要查询所有记录,其中DuckbillId是DuckbillId中的一个值,DateTime字段位于EarliestToShow和LatestToShow之间。根据下面的说明,伪SQL应该是:
从duckbillId中的duckbillId和DateVal位于最早的ToShow和最晚的ToShow(含)之间的Platypi中选择*
我更喜欢一些基本SQL选择、插入、更新和删除(CRUD操作)的工作示例;其次是Lambda,它的语法在我看来非常复杂
林克也会没事的
更新
我在SQLite Net的页面上找到了一些示例(http://code.google.com/p/sqlite-net/)这让我想到了这一点,它至少汇编了:
public List<Locations> GetLocationsForPlatypiAndTimeRange(List<string> PlatypiIds, DateTime EarliestToShow,
DateTime LatestToShow)
{
var db = new SQLite.SQLiteConnection(SQLitePath);
StringBuilder sb = new StringBuilder();
foreach (String s in PlatypiIds)
{
sb.Append(string.Format("{0},", s));
}
sb.Remove(sb.Length - 1, 1); // remove the superfluous trailing comma
return
db.Query<Locations>(
"Select * from Locations Where PlatypusId in (?) and SentTimeLocal >= ? and SentTimeLocal <= ? Order by SentTimeLocal",
sb.ToString(), EarliestToShow, LatestToShow);
}
public List GetLocationsForPlatypiAndTimeRange(列出platypids、DateTime EarliestToShow、,
DateTime LatestToShow)
{
var db=new SQLite.SQLiteConnection(SQLitePath);
StringBuilder sb=新的StringBuilder();
foreach(platypids中的字符串s)
{
sb.Append(string.Format(“{0},”,s));
}
sb.Remove(sb.Length-1,1);//删除多余的尾随逗号
返回
数据库查询(
“根据我正在评估您使用的代码示例,从PlatypusId in(?)和SentTimeLocal>=?和SentTimeLocal的位置选择*。尝试查看它的和。有两个使用SQL语法的工作示例应该可以帮助您
我不确定您尝试了哪些示例,但您提到的类名肯定不是sqlite net的一部分,它们听起来好像来自。。其中(x->x.Duckbillid==someValue)如果您只返回一个记录,考虑使用<代码>单< /代码>或<代码> SingleOrDefault <代码>代替<代码> > <代码> >如果内存服务,<代码> ASYNC 和<代码>等待/代码>已经执行必要的回旋以使查询异步,因此您不需要<代码> ToListAsync <代码>,而只需<代码> tol。ist
。如果要检查列表中的项目,请使用Contains
。在Where
中,“between”只需要两个条件。可以在这里找到几个Linq示例:当然这是一个真实的问题;但是,这里的一些注释不是真实的答案。是的,我相信你说得对,它们来自ADO.NET提供商。