I've created a repository with a complete example of what I'm trying to do.
I have the following schema:
class Order
{
public int OrderId { get; set; }
}
class LineItem
{
public int LineItemId { get; set; }
public int OrderId { get; set; }
}
I'm using ServiceStack.OrmLite to left join Order with LineItem, using this code:
var query = db.From<Order>()
.LeftJoin<LineItem>()
.Where(o => o.OrderId == 1);
var results = db.SelectMulti<Order, LineItem>(query);
SelectMulti() returns a List<Tuple<Order, LineItem>>. When an order has no line items, I'm getting back new LineItem() instead of null.
I expected to get null back so I could tell the difference between "no line items exist for this order" and "this order has a line item with default values".
I could check for the line item's OrderId being equal to the order's OrderId, but in theory I could have an order with OrderId 0, so in that case I wouldn't be able to tell.
Is there a better way to do this left join with OrmLite?