private static HqlProjectionQuery GetBaseVisitPractitionerQuery(VisitSearchCriteria visitSearchCriteria, VisitPractitionerSearchCriteria practitionerSearchCriteria) { var hqlFrom = new HqlFrom(typeof(Visit).Name, "v"); hqlFrom.Joins.Add(new HqlJoin("v.Practitioners", "vp")); var query = new HqlProjectionQuery(hqlFrom); query.Conditions.AddRange(HqlCondition.FromSearchCriteria("vp", practitionerSearchCriteria)); query.Conditions.AddRange(HqlCondition.FromSearchCriteria("v", visitSearchCriteria)); return(query); }
private static HqlProjectionQuery GetBaseResultRecipientQuery(OrderSearchCriteria orderSearchCriteria, ResultRecipientSearchCriteria recipientSearchCriteria) { var hqlFrom = new HqlFrom(typeof(Order).Name, "o"); hqlFrom.Joins.Add(new HqlJoin("o.ResultRecipients", "rr")); var query = new HqlProjectionQuery(hqlFrom); query.Conditions.AddRange(HqlCondition.FromSearchCriteria("rr", recipientSearchCriteria)); query.Conditions.AddRange(HqlCondition.FromSearchCriteria("o", orderSearchCriteria)); return(query); }
public IList <ModalityProcedureStep> Find(ModalityProcedureStepSearchCriteria mpsCriteria, ProcedureSearchCriteria procedureCriteria) { var hqlFrom = new HqlFrom(typeof(ModalityProcedureStep).Name, "mps"); hqlFrom.Joins.Add(new HqlJoin("mps.Procedure", "rp", HqlJoinMode.Inner, true)); var query = new HqlProjectionQuery(hqlFrom); query.Conditions.AddRange(HqlCondition.FromSearchCriteria("mps", mpsCriteria)); query.Conditions.AddRange(HqlCondition.FromSearchCriteria("rp", procedureCriteria)); return(ExecuteHql <ModalityProcedureStep>(query)); }
public IList <ConfigurationDocument> Find(ConfigurationDocumentSearchCriteria documentCriteria, ConfigurationDocumentBodySearchCriteria bodyCriteria, SearchResultPage page) { var hqlFrom = new HqlFrom(typeof(ConfigurationDocument).Name, "doc"); hqlFrom.Joins.Add(new HqlJoin("doc.Body", "body")); var query = new HqlProjectionQuery(hqlFrom); query.Selects.Add(new HqlSelect("doc")); query.Conditions.AddRange(HqlCondition.FromSearchCriteria("doc", documentCriteria)); query.Conditions.AddRange(HqlCondition.FromSearchCriteria("body", bodyCriteria)); query.Page = page; return(ExecuteHql <ConfigurationDocument>(query)); }
/// <summary> /// NHibernate has a bug where criteria that de-reference properties not joined into the From clause are not /// always handled properly. For example, in order to evaluate a criteria such as "ps.Scheduling.Performer.Staff.Name like ?", /// NHiberate will inject a theta-join on Staff into the SQL. This works ok by itself. However, when evaluating a criteria /// such as "ps.Scheduling.Performer.Staff.Name.FamilyName like ? or ps.Performer.Staff.Name.FamilyName like ?", NHibernate /// injects two Staff theta-joins into the SQL, which incorrectly results in a cross-join situation. /// This method modifies any query that has criteria on ps.Scheduling.Performer.Staff or ps.Performer.Staff, /// by adding in explicit joins to Staff for these objects, and then substituting the original conditions /// with conditions based on these joins. /// </summary> public static void NHibernateBugWorkaround(HqlFrom from, IList <HqlCondition> conditions, Converter <string, string> remapHqlExprFunction) { var scheduledStaff = remapHqlExprFunction("ps.Scheduling.Performer.Staff"); var performerStaff = remapHqlExprFunction("ps.Performer.Staff"); for (var i = 0; i < conditions.Count; i++) { var condition = conditions[i]; if (condition is HqlJunction) { NHibernateBugWorkaround(from, ((HqlJunction)condition).Conditions, remapHqlExprFunction); } else if (condition.Hql.StartsWith(scheduledStaff)) { // add join for sst (scheduled staff) if not added if (!CollectionUtils.Contains(from.Joins, j => j.Alias == "sst")) { from.Joins.Add(new HqlJoin(scheduledStaff, "sst", HqlJoinMode.Left)); } // replace the condition with a new condition, using the joined Staff var newHql = condition.Hql.Replace(scheduledStaff, "sst"); conditions[i] = new HqlCondition(newHql, condition.Parameters); } else if (condition.Hql.StartsWith(performerStaff)) { // add join for pst (performer staff) if not added if (!CollectionUtils.Contains(from.Joins, j => j.Alias == "pst")) { from.Joins.Add(new HqlJoin(performerStaff, "pst", HqlJoinMode.Left)); } // replace the condition with a new condition, using the joined Staff var newHql = condition.Hql.Replace(performerStaff, "pst"); conditions[i] = new HqlCondition(newHql, condition.Parameters); } } }