OrmLite Join Aliases
Joining on the same table multiple times results in incorrect SQL being generated by OrmLite.
Table aliases need to be added automatically by OrmLite so the correct SQL is generated when joining on the same table multiple times.

Support for Typed JOIN aliases were added in v4.0.62: https://github.com/ServiceStack/ServiceStack.OrmLite#join-aliases
-
Michael Daly commented
Good to know, thanks
-
You can use a CustomJoin and Custom Select in the interim to handle multiple table joins, see:
var q = db.From<Sale>()
.CustomJoin("LEFT JOIN Contact seller on (Sale.{0} = seller.Id)".Fmt("SellerId".SqlColumn()))
.CustomJoin("LEFT JOIN Contact buyer on (Sale.{0} = buyer.Id)".Fmt("BuyerId".SqlColumn()))
.Select(@"Sale.*
, buyer.{0} AS BuyerFirstName
, buyer.{1} AS BuyerLastName
, seller.{0} AS SellerFirstName
, seller.{1} AS SellerLastName"
.Fmt("FirstName".SqlColumn(), "LastName".SqlColumn()));q.Where(x => x.TenantId == tenantId);
var sales = db.Select<SaleView>(q);