LoadSelect with paramteters for children

I need to be able to pass parameter values to LoadSelect’s children. I have tried everything I can think of right up to Reflection. Can you please help me with a possible solution? Is there something I missed?

Can you share more info of what SQL query you are trying to generate and use of LoadSelect code, so we can understand the issue you’re having a bit better? If you can include relate schema/model as well. Thanks.

So the Parent Query has a parameter of UserLoginID this is set from the Service’s authentication. Lets call it SalesOrders. SalesOrders have SalesOrderLines referenced children. These views are really cartesian results to handle the “ownership” of those sales orders and lines through some configuration tables. I would like the SalesOrderLines to be joined with the SalesOrders on UserLoginID as well as the SalesOrderId.

Without the schema or code, it’s a bit tricky to understand the problem and where the issue might be, but here is an example (not sure how close to what you have) that might be of use.

public class SalesOrder
{
    [AutoIncrement]
    public int Id { get; set; }
    
    public string Name { get; set; }
    
    [References(typeof(UserAuth))]
    public int UserAuthId { get; set; }
    
    [Reference]
    public List<SalesOrderLine> SalesOrderLines { get; set; }
}

public class SalesOrderLine
{
    [AutoIncrement]
    public int Id { get; set; }
    
    public string Name { get; set; }
    
    [References(typeof(SalesOrder))]
    public int SalesOrderId { get; set; }
    
    [References(typeof(UserAuth))]
    public int UserAuthId { get; set; }
}

And the query:

var query = Db.From<SalesOrder>()
                .Join<SalesOrderLine>((x, y) => x.UserAuthId == userId && y.SalesOrderId == x.Id)
                .Where(x => x.UserAuthId == userId)
                .SelectDistinct();

var results = Db.LoadSelect(query);

After seeding db with several SalesOrders with several SalesOrderLine, I get returned the expected instances of SalesOrder with related number of children each within results.

If this doesn’t help, you’ll need to share an example of the issue so I can reproduce. Thanks.