This is my case:
var q = DB.From<LRDAnalisi>()
.Join<LRDAnalisi, LRDContenitore>((dana, dcont) => dana.ContenitoreId == dcont.Id, DB.TableAlias("c"))
.Join<LRDAnalisi, LRDProfiloAnalisi>((dana, dprofana) => dana.Id == dprofana.AnalisiId, DB.TableAlias("dprofana"))
.Where<LRDProfiloAnalisi>(dprofana => Sql.TableAlias(dprofana.ProfiloAnalisiId, "dprofana") == null)
.OrderBy<LRDAnalisi>(x => x.Ordine)
.SelectDistinct<LRDAnalisi, LRDProfiloAnalisi, LRDContenitore>((dana, dprofana, dcont) =>
new //ProfiloAnalisiDTO
{
Id = Sql.TableAlias(dprofana.Id, "dprofana"),
AnalisiId = dana.Id,
Codice = dana.Codice,
Descrizione = dana.Descrizione,
ContenitoreId = Sql.TableAlias(dcont.Id, "c"),
ContenitoreCodice = Sql.TableAlias(dcont.Codice, "c"),
ContenitoreDescrizione = Sql.TableAlias(dcont.Descrizione, "c"),
dana.Ordine, // serve solo per ordinare, nel DTO restituito non c'e' questo campo
VersioneRecord = Sql.TableAlias(dprofana.VersioneRecord, "dprofana")
});
The query crashed with: The multi-part identifier "LRDPROFILOANALISI.DANALISIID" could not be bound.
.
This is the SQL Statement with the error marked:
SELECT DISTINCT
dprofana."IDDPROFILOANALISI" AS Id
, "LRDANALISI"."IDDANALISI" AS "AnalisiId"
, "LRDANALISI"."CODICE"
, "LRDANALISI"."DESCRIZIONE"
, c."IDDCONTENITORE" AS ContenitoreId
, c."CODICE" AS ContenitoreCodice
, c."DESCRIZIONE" AS ContenitoreDescrizione
, "LRDANALISI"."ORDINE"
, dprofana."VERSIONERECORD" AS VersioneRecord
FROM "LRDANALISI"
INNER JOIN "LRDCONTENITORI" AS "c" ON("LRDANALISI"."DCONTENITOREID" = "c"."IDDCONTENITORE")
INNER JOIN "LRDPROFILOANALISI" AS "dprofana" ON("LRDANALISI"."IDDANALISI" = "LRDPROFILOANALISI"."DANALISIID") -- error here
WHERE( dprofana."DPROFILOANALISIID" IS NULL
)
ORDER BY "LRDANALISI"."ORDINE";
By the way, the query still contains missing SQL aliases that results in missing bindings after query execution, with no error from OrmLite. We are full of cases where columns does not bind at all with the anonymous object. We may need to talk about them in a new thread.