I am using Realm database for storing data locally on my device. In the application a user can see a list of books and apply Filters/Sorting on them. A book is a Pojo object which has a Title, Author(string), Status(Enum) and Publish-Date(time stamp). The user of the application can filter books based on those four fields, there are more fields on the object but for simplicity I am only using 4 at the moment.
I am trying to create a dynamic query builder where all the selected filters will be applied on the query.
What I have seen in the documentation is that we can query realm like this
var allBooks = realm.All<Book>().Where(book =>
book.Title== "Star wars" ||
book.Status== "Sold");
what I want is to construct the query on my own by passing the list of filters int the method. I was thinking of creating a wrapper class with Key/Value pair and assigning the name of the filter and the value. Then I could pass a list of those to a method. My question is how construct the query builder from a list of key/value where the key is the object field like "Title", "Status" and the value is "Star wars", "Sold".
Any help will be greatly appreciate.
Status? In question you said that is is enum, but later in code you comparing it like a string. - Aleks AndreevIQueryable<T>so the "easiest" way is to construct an expression tree (it isn't too hand once you get the hang of the API, getting the hang of the API isn't so easy due to lack of non-trivial examples). - Richard