RavenDB - create dynamic query with OR filters

I need to create a query at runtime that uses OR statuses. If I use the method below to build a query, it's all together. I really need each filter value to be OR in order for this query to work correctly.

public class IdAndRole
    public string Id {get;set;}
    public string Role {get;set;}

var idAndRoles = session.Query<IdAndRole, Roles_ById>();
foreach(var filter in filterValues)
    idAndRoles = idAndRoles.Where(x => x.In(filter.Id) && x.In(filter.Role));



(filter[0].Id == value1 && filter[0].Role == role1) ||(filter[1].Id == value2 && filter[1].Role == role2)



source to share

2 answers

Phil, you can go down to LuceneQuery and this will allow you to closely monitor your query.



You can use PredicateBuilder to create a request.

var predicate = PredicateBuilder.False<IdAndRole>();
foreach (var filter in filterValues)
     predicate = predicate.Or( x => x.In(filter.Id) && x.In(filter.Role) );

var idAndRoles = session.Query<IdAndRole,Roles_byId>()
                        .Where( predicate );




All Articles