Script sendToAutoQuery Skips Custom Implementation


I am going through the docs and found this inconsistency. I may be missing something so asking for help.

Given the scenario below if I call this AutoQuery through Code/Postman then I hit the breakpoint in my custom implementation and it’s all good. But when I call this through sendToAutoQuery in a script page it never hits the breakpoint and my custom code is not executed.


    public class QueryCategory : QueryDb<Category>    {    }

    public class MyQueryServices : Service
        public IAutoQueryDb AutoQuery { get; set; }

        public object Any(QueryCategory query)
            using var db = AutoQuery.GetDb(query, base.Request);
            var q = AutoQuery.CreateQuery(query, base.Request, db);
            return AutoQuery.Execute(query, q, base.Request, db);

Yeah the AutoQueryScripts doesn’t invoke the Service, i.e. it’s just calling the IAutoQuery APIs directly, e,g. the same dependency that your custom implementation are using.

You should be able to use sendToGateway to invoke ServiceStack Services.

Here is the code in the page:

{{ sendToAutoQuery({NameContains: "Moth"}, 'QueryCategory') |> htmlDump }}

and the start up code:

Plugins.Add(new SharpPagesFeature {
    ScriptMethods = { new AutoQueryScripts(), new InfoScripts(), new DbScriptsAsync() },
    ScanAssemblies = new List<Assembly>{Assembly.GetExecutingAssembly()},
    RenderExpressionExceptions = true

You need to use sendToGateway to invoke ServiceStack Services, e.g:

{NameContains "Moth"} |> sendToGateway('QueryCategory') |> toResults |> htmlDump

I did that and it’s hitting the custom implementation but none of the filter condition like NameContains: “Moth” or Id: 1 are working from #servicestack:sharp-script. They are working when I call them from Code.

That’s because when invoking a Service the body is used to populate the Request DTO which requires the property to exist. So you’ll need to add any properties you wish to use.