0

How can I do an auto query with "or" operation like - http://localhost/rockstars/first_name=MikeORlast_name=Smith

SMV
  • 49
  • 1
  • 6

1 Answers1

0

See the Section on changing AutoQuery Behavior where you can change the behavior of every field by annotating Services with [Query(QueryTerm.Or)], e.g:

[Query(QueryTerm.Or)]
public class QueryRockstars : QueryBase<Rockstar> {}

Otherwise if you only want to some of the fields to have "OR" behavior you can decorate them individually with:

public class QueryRockstars : QueryBase<Rockstar>
{
    [QueryField(Term=QueryTerm.Or)]
    public string FirstName { get; set; }

    [QueryField(Term=QueryTerm.Or)]
    public string LastName { get; set; }
}

However from a Services design POV applying different behavior is not recommended since ideally each of the fields should have the same semantics.

With the above Request DTO's you can now query it with:

/rockstars?FirstName=Mike&LastName=Smith
Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • I tried the example you gave above but when I run the query like this - http://localhost/rockstars/first_name=Mikeorlast_name=Smith it gives "0" result set even though data is present – SMV Jul 30 '15 at 18:25
  • just "&" in between ? – SMV Jul 30 '15 at 18:45
  • I tried public class QueryRockstars : QueryBase { [QueryField(Term=QueryTerm.Or)] public string FirstName { get; set; } [QueryField(Term=QueryTerm.Or)] public string LastName { get; set; } } but this /rockstars?FirstName=Mike&LastName=Smith still give "0" result set – SMV Jul 30 '15 at 20:58
  • @SMV I've just [added a test for this](https://github.com/ServiceStack/ServiceStack/commit/b84f9848f5a9aea82c650be83497e5e05fb24c04) which works as advertised. – mythz Jul 30 '15 at 21:10