Je voudrais créer DetachedCriteria exerceraient quelque chose de similaire au code SQL suivant:NHibernate DetachedCriteria - comment utiliser quelque chose comme sur le plateau-joint externe NVL Oracle
select *
FROM PRICELIST pl
LEFT OUTER JOIN PRICELISTDURATIONSHIFT sh ON sh.PRICELISTID = pl.ID
WHERE sh.CUSTOMERID = :cust
AND nvl(sh.DATEFROM, pl.DATEFROM) <= :dt
ORDER BY nvl(sh.DATEFROM, pl.DATEFROM) DESC
Je suis en mesure de gauche external-rejoignez la classe/table PriceListDurationShift
et ajoutez la contrainte Customer, mais je ne suis pas capable de comprendre comment ajouter quelque chose comme la restriction nvl (sh.DATEFROM, pl.DATEFROM) < =: dt.
J'apprécierais tout conseil pour cet exemple et également tout conseil sur les matériaux de NHibernate sur l'interrogation DetachedCriteria avancée.
nous espérons que cela fonctionnerait:
var priceLists = priceListRepo.FindAll(DetachedCriteria.For<PriceList>("pl")
.CreateCriteria((PriceList x) => x.PriceListDurationShifts,() => shift,
JoinType.LeftOuterJoin)
.Add<PriceListDurationShift>(x => x.Customer == cust)
.Add(Expression.Or(
Expression.And(Restrictions.IsNull("shift.DateFrom"),
Restrictions.Le("pl.DateFrom", dt.DateTo)),
Expression.And(Restrictions.IsNotNull("shift.DateFrom"),
Restrictions.Le("shift.DateFrom", dt.DateTo))
))
)
.ToList();
il pourrait être probablement résolu avec Projections.SQLFunction comme dans ce cas: http://stackoverflow.com/questions/793166/how-to-user-year-and-month-functions-in-nh- critères-api – Buthrakaur