见代码:
var lines = new List<PosLine>(){
new PosLine{Name="John", Address="dummy1", Tstamp=DateTime.Now},
new PosLine{Name="Jane", Address="dummy2", Tstamp=DateTime.Now}
};
using(var db = new LiteDatabase(@"test.db"))
{
var posLines = db.GetCollection<PosLine>("POS");
foreach(var line in lines)
{
var id = posLines.Insert(line);
Console.WriteLine("id=" + id.ToString());
}
var names = posLines.FindAll().Select(p => p.Name).ToList();
foreach(var name in names)
{
Console.WriteLine("name=" + name);
}
}
该行var names = posLines.FindAll().Select(p => p.Name).ToList();
尝试获取“名称”列表,但在这种情况下,它是全表扫描。有没有办法避免全表扫描,比如我在“名称”属性上创建一个索引,然后从该索引中获取所有名称?