Fernando Juarez
Fernando Juarez

Reputation: 55

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

Upvotes: 4

Views: 249

Answers (1)

mythz
mythz

Reputation: 143359

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

Upvotes: 3

Related Questions