Page 1 of 1

Auto Query A bit Easier  Topic is solved

PostPosted: Mon Nov 28, 2022 1:45 pm
by SBarnes
In the past in adding auto queries I have created a service to run the auto queries today I have discovered an easier way in the configure method of your plugin as well as having the add route code add the following two lines and service stack will scan the plugin for auto query classes, make sure you plugin has a higher execution order than the REST API plugin though.



Code: Select all
var dll = GetType().Assembly;
AppHost.GetPlugin<AutoQueryFeature>().LoadFromAssemblies.Add(dll);

Re: Auto Query A bit Easier

PostPosted: Fri Feb 03, 2023 5:24 pm
by SBarnes
Well I worked out the answer for myself its as simple as on your service class declare the AutoQuery property like this


Code: Select all
public IAutoQueryDb AutoQuery { get; set; }


then inside your method do this, which is based upon the documentation of doing a custom auto query.

Code: Select all
      var req =  new JiwaFinancials.Jiwa.JiwaServiceModel.Tables.DB_MainQuery();
                var q = AutoQuery.CreateQuery(req, base.Request, Db);
                var result = AutoQuery.Execute(req, q, base.Request, Db);