1

I enjoy working with LiteDB in Xamarin.Forms. What is the best practice for getting list of objects from a table using list of ids or indexes in condition? Currently, it looks for me like this:

_db.GetCollection<T>().FindAll().Where(q => listValues.Contains(Convert.ToInt32(q.GetProperty(idColumnName))));

listValues - list of searched ids. idColumnName - column with indexes.

But FindAll retrives all records from LiteDB. Is there any more efficint options without full scanning?

Serg
  • 95
  • 8

2 Answers2

4

Use the query in the Find method instead which will only retrieve entries based on your query rather than the full data set. This, according to the LiteDB's guidance, is more efficient than Linq queries on the full data returned: https://github.com/mbdavid/LiteDB/wiki/Queries

So your query would look like as follows

_d.GetCollection<T>().Find(q => listValues.Contains(Convert.ToInt32(q.GetProperty(idColumnName))))
MBT86
  • 51
  • 4
0

I think you can just use collection.Query().Where("Column", 1,2,3) for this

Sample

YoCom
  • 21
  • 4