I have a lot of query that does not bind variables correctly when using manual selects.
Note that I’m using AliasAttribute
on every table and every field I have defined, and that seems to lead to problems (usually non-binded fields does not have the AS
clause in the Select list).
Here is an example:
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")
});
This query seems to work fine.
Now I change ContenitoreId
“formula” to dana.ContenitoreId
. Note that the field is used in the first INNER JOIN
so while I’m using a different column, the values are absolutely the same.
The query won’t successfully bind ContenitoreId
anymore, and the field will always 0, no matter what. This query also is full of JoinAlias\TableAlias
. Those would not be needed in this specific query, but we have to use because basically every field of queries like that because otherwise some fields will never bind to the property of the anonymous object.
Please help us because we have a lot of query with the anonymous projection and that means that a the current state we cannot trust OrmLite when doing this kind of queries.