Search code examples
servicestackormlite-servicestack

ServiceStack AutoQuery, Multiple IJoin


In my example I have the following database structure. Order has many OrderLine, which has one Product.

Image illustrating the above description.

I am trying to return the following DTO:

public class OrderLineDto {
   public int Id { get; set; }
   public int Quantity { get; set; }
   public string OrderType { get; set; }
   public string ProductName { get; set; }
}

This should be possible by use of the following Query Route:

[Route("/orderlines")]
public class FindOrderLines : QueryBase<OrderLine, OrderLineDto>,
  IJoin<OrderLine, Order>, 
  IJoin<OrderLine, Product>
{ }

What I am trying to do here is join OrderLine in both directions to bring in Type from Order, and Name from Product and return it in an OrderLineDto.

I am able to do these things individually by only using one IJoin, however AutoQuery appears only to use the first IJoin interface declaration, and does not perform the second join.

If I attempt to do a join like this: IJoin<OrderLine, Order, Product>

I get the following exception: Could not infer relationship between Order and Product

Is it possible to achieve what I am trying to do here with auto query or should I go back to writing standard REST services, abandoning AutoQuery?


Solution

  • I have submitted a pull request to ServiceStack which will now allow this behavior.

    https://github.com/ServiceStack/ServiceStack/pull/955