I want to execute this Query with CreateCriteria, I dont know if it’s possible to add a OR clause to the ON part of the JOIN like this: (TZ.CodigoPuesto1_id = CP.Id or TZ.CodigoPuesto2_id = CP.Id), here is the complete query:
SELECT TZ.*
FROM ConfigLinea as CL
JOIN Puesto as P ON P.ConfigLinea_id = CL.Id
join CodigoPuesto as CP ON CP.Puesto_id = P.Id
Join Trazabilidad as TZ ON
(TZ.CodigoPuesto1_id = CP.Id or TZ.CodigoPuesto2_id = CP.Id)
WHERE TZ.Codigo1 = '{0}' OR TZ.Codigo2 = '{1}' AND CL.Id = {2}
So far I tried this, but is not generating the Query I need:
IList<Trazabilidad> result = session.CreateCriteria(typeof(Trazabilidad), "TZ")
.CreateAlias("CodigoPuesto1", "CP1")
.CreateAlias("CodigoPuesto2", "CP2")
.Add(Expression.Disjunction() //esto es un OR
.Add(Restrictions.Eq("TZ.Codigo1", codigo))
.Add(Restrictions.Eq("TZ.Codigo2", codigo))
)
.Add(Expression.Disjunction() //esto es un OR
.Add(Restrictions.Eq("P1.ConfigLinea", cl))
.Add(Restrictions.Eq("P2.ConfigLinea", cl))
)
.List<Trazabilidad>();
Thanks in advance
Without your domain model it’s hard to actually test this, but I think you’ll want something like this. Basically the idea is the use the version of CreateAlias that lets you pass an ICriterion in as a parameter.