我是LiteDB的新手,想一次性执行两个或多个查询。
我希望能够在我的数据库中搜索某个客户,并且由于会有多个具有相似名称的客户,我希望将它们全部返回并按Descending (Id or Date) Order对它们进行排序。我有两个功能即兴但分开,所以我正在寻找一种将 Search 和 Sort 组合成一个 Query的方法。
这是主要的搜索功能:
private void search_btn_Click(object sender, RoutedEventArgs e)
{
using (var dataBase = new LiteDatabase(dbConnectionString))
{
// Stranka = Customer
var collection = dataBase.GetCollection<Stranka>("stranka");
// Search for a customer name whom I enter in the searchName_tb
var query = collection.Find(Query.Where("Ime_Priimek",
x => x.AsString.Contains(searchName_tb.Text)));
// Currently I'm doing everything with ListView, so I clear it
// to make room for resulting data to be shown
lvStranke.Items.Clear();
foreach (var customer in query)
{
lvStranke.Items.Add(customer);
}
}
}
这是我在加载/刷新时按降序排序的版本:
public void LiteDB_ShowAll()
{
using (var dataBase = new LiteDatabase(dbConnectionString))
{
var collection = dataBase.GetCollection<Stranka>("stranka");
lvStranke.Items.Clear();
var count = collection.Count(Query.All());
// From last ID to first (Descending)
for (int i = count; i >= 1; i--)
{
lvStranke.Items.Add(collection.FindById(i));
}
}
}