Generic Query DTO

I think I am missing something here. I want to be able to query a DTO on the fly but I can’t figure out what I am missing. I have a class that I would like to be able to filter by any column. Do I have to list all columns in the QueryDB based class? I would like to be able to do the same thing you can do from the browser with the client without having to build the url? Is this possible? Sorry if this is simple I just can’t seem to find anything about it.

Derek

Not sure what you mean by on-the-fly, you can’t query an AutoQuery Service that doesn’t exist but you don’t need to specify all the table columns. Querying an AutoQuery Request DTO without specifying columns available uses AutoQueries implicit conventions.

Have a look ServiceStack.Admin UI which uses a simple query builder to construct a querystring with your chosen filters.

I was talking about a contractless request I.e. no properties. But I was wondering how the JsonServiceClient utilized it. There are no “properties”.

As you’d expect the Typed Service Clients can only de/serialize Typed DTOs.

You could specify a custom relativeUrl with the query and deserialize it into the Response DTO:

var client = new JsonServiceClient(uri);
var response = client.Get<QueryResponse<Table>>("/query?Field=Value");

Otherwise if you don’t want to declare an explicit Service Contract you can also access the raw JSON with HTTP Utils which you can deserialize into an untyped collection with JS Utils, e.g:

var json = url.GetJsonToString();
var obj = JSON.parse(json);
obj.PrintDump();
1 Like

That makes sense to me. I will just build the relative Url and return a QueryResponse. Thanks for the quick turnaround !

1 Like