Fernando Juarez Fernando Juarez - 18 days ago 7
C# Question

Servicestack - OR operator for consuming autoquery rdbms API

Is there a way to use OR operator for conditions in queries. I know that the modifier

[QueryDbField(Term=QueryTerm.Or)]
can be used but this will change the behavior of the property always. Maybe some times I need to query with AND and some times I need to query with OR, with the same field.
Something like

state = la AND amount = 1000 OR totalamount=1000

become

{url}?state=la&amount=1000&ORtotalamount=1000

Answer

You can't specify an OR condition on the QueryString adhoc like this but you could potentially use a custom template to create a custom query, e.g:

public class Query : QueryDb<Table>
{
    public int Amount { get; set; }
    public int TotalAmount { get; set; }

    [QueryDbField(Template = "Amount = {Value} OR TotalAmount = {Value}")]
    public int AnyAmount { get; set; }
}

Which should let you then query with:

?anyamount=1000