AutoQuery Service

I’m writing a service that encapsulates DHCP management (the service doesn’t matter, but it might be easier to understand the snippets.) I have a route like so in my model:

public class DhcpScope
    {
        [Description("The Scope Id")]
        public string ScopeId { get; set; }

        [Description("The subnet mask of the scope")]
        public string SubnetMask { get; set; }

        [Description("Name")]
        public string Name { get; set; }

        [Description("The state of the scope.")]
        public SubnetState State { get; set; }

        [Description("The starting range of the scope.")]
        public string StartRange { get; set; }

        [Description("The end range of the scope.")]
        public string EndRange { get; set; }

        [Description("Lease duration of the scope.")]
        public string DateTime { get; set; }
    }

    public enum SubnetState
    {
        Active,
        Inactive
    }
    [Route("/dhcp/servers/{Name}/scopes", "GET", Summary = "Gets all DHCP scopes for the given server.")]
    public class GetDhcpScopes : IReturn<List<DhcpScope>>
    {
        [Description("The FQDN of the DHCP server")]
        public string Name { get; set; }
    }

(I’m skipping over the implementation in my Service Interface, because that’s working just fine)

I’d like to use make that route searchable by using AutoQuery, so I added:

 [Route("/dhcp/servers/{Name}/scopes/search", "GET", Summary = "Searches DHCP scopes.")]
    public class SearchDhcpScopes : QueryData<DhcpScope>
    {
        [Description("The FQDN of the DHCP server")]
        public string Name { get; set; }     
    }

and in my Global.asax:

Plugins.Add(new AutoQueryDataFeature {MaxLimit = 100}                   
                    .AddDataSource(ctx => ctx.ServiceSource<DhcpScope>(ctx.Dto.ConvertTo<GetDhcpScopes>(), HostContext.Cache, TimeSpan.FromMinutes(5))));

However, the resulting AutoQuery route doesn’t return any results. When I step through the code, it looks like AutoQuery automatically tries the filter the DhcpScope data using the parameters in my request (Name), even though the resulting data (DhcpScope) doesn’t have a Name field. Is this something I can work around?

I don’t understand? It does have a `Name field:

public class DhcpScope
{
    [Description("The Scope Id")]
    public string ScopeId { get; set; }

    [Description("The subnet mask of the scope")]
    public string SubnetMask { get; set; }

    [Description("Name")]
    public string Name { get; set; }
    ...
}

Oh duh, looked right past it. That’s the name of the scope, not the name of the server, so that’s what was confusing things. The method that retrieves scopes refers to it as “Name”, so I just aliased it:

[Description("Name of the scope")]
[Alias("Name")
public string ScopeName { get; set; }

… and now all is well.

Thanks for second pair of eyes!

1 Like