Search code examples
c#servicestackormlite-servicestackservicestack-autoquery

AutoQuery can't query nested object


AutoQuery could not find field

I have the following clases:

[Route("/query/domains")]
public class QueryDomains : QueryDb<Domain, DomainList>
{
    public int MajesticApiDataTF { get; set; }
}

public class DomainList
{
    public string DomainName { get; set; }
    public int MajesticApiDataTF { get; set; }
}

[Route("/domain/{Id}")]
public class Domain : IReturn<DomainResponse>
{
    [AutoIncrement]
    public int Id { get; set; }

    [Index(Unique = true)]
    [StringLength(70)]
    public string DomainName { get; set; }  

    [Reference]
    public MajesticApiData MajesticApiData { get; set; }

}

public class MajesticApiData
{
    [AutoIncrement]
    public int Id { get; set; }
    public int TF { get; set; }
    [ForeignKey(typeof(Domain), OnDelete = "CASCADE")]
    public int DomainId { get; set; }
}

When I try querying in AutoQuery viewer by TF like this:

http://localhost:5000/query/domains?MajesticApiDataTF%3E=1&MajesticApiDataTF%3E=1

All domain results come back without filtering and every TF value shows 0.

I tried adding IJoin:

public class QueryDomains : QueryDb<Domain, DomainList>, IJoin<Domain, MajesticApiData>

But then the query returns no results.

I have checked in database and TF does have a value. I am using PostgreSql provider.

I want it to show the TF value and be filterable. What did I get wrong?

Edit:

OK so the issue appears to be that the greater than operator is not supported.

If I do:

query/domains?MajesticApiDataTF>5&include=Total

Then debug output shows

2018-07-07 01:54:00.1555||DEBUG|OrmLiteReadCommandExtensions|SQL: SELECT COUNT(*) "COUNT(*)"
FROM "domain" INNER JOIN "majestic_api_data" ON
("domain"."id" = "majestic_api_data"."domain_id")
WHERE "majestic_api_data"."tf" = :0
PARAMS: :0=0

But if I do:

query/domains?MajesticApiDataTF=5&include=Total

Then there is a param value passed.

2018-07-07 01:57:08.7809||DEBUG|OrmLiteReadCommandExtensions|SQL: SELECT COUNT(*) "COUNT(*)"
FROM "domain" INNER JOIN "majestic_api_data" ON
("domain"."id" = "majestic_api_data"."domain_id")
WHERE "majestic_api_data"."tf" = :0
PARAMS: :0=5

Is it possible to use greater than/less than on a joined property? If not how do I add that in myself?

:fix

I set it to nullable int int? MajesticApiDataTF and then it worked


Solution

  • As you may suspect, AutoQuery does not support querying nested/referenced types.

    Also Joins in AutoQuery need to follow the implicit Reference conventions that must exist in the 2 tables being joined, they do not query or change how referenced data is loaded or filtered.

    AutoQuery only lets you query the target type (in this case Domain), there is no ability to filter the referenced types that are loaded.