public override SQ.Entity OnBuildQueryNode(QueryBuilderContext context, bool allowReuse) { // Find a node if (ChildContainer.ChildEntityNodes.Count > 1) { throw new Exception("Cross-join in report calculations are unsupported."); } SQ.Entity reportNode; if (ChildContainer.ChildEntityNodes.Count == 0) { reportNode = new SingleRowNode( ); } else { reportNode = ChildContainer.ChildEntityNodes.Single( ).BuildQueryNode(context, false); } // Attach conditions ScalarExpression condition = Right.BuildQuery(context); if (reportNode.Conditions == null) { reportNode.Conditions = new List <ScalarExpression>(); } reportNode.Conditions.Add(condition); return(reportNode); }
/// <summary> /// Handles a custom join. /// </summary> /// <param name="singleRowNode"></param> /// <param name="parentTable">The parent table.</param> /// <param name="sqlQuery">The SQL query that the table will be created in.</param> /// <returns>The table to use for upward joins.</returns> private EntityTables RegisterSingleRowNode(SingleRowNode singleRowNode, SqlTable parentTable, SqlQuery sqlQuery) { SqlTable table = sqlQuery.CreateJoinedTable("(values(1))", "t", parentTable, JoinHint.Unspecified, null, null); table.NameContainsSql = true; table.FullTableAlias = table.TableAlias + "(val)"; table.FilterByTenant = false; return(new EntityTables(table)); }
public override SQ.Entity OnBuildQueryNode(QueryBuilderContext context, bool allowReuse) { // Hack to fix count(convert(Manager,context()).[Direct Reports]) // A more general fix should ensure that we do not reuse a context here that is already used in the parent scope.. or something?? var nodesToProcess = ChildContainer.ChildEntityNodes; if (nodesToProcess.Count == 1 && nodesToProcess[0] is GetRootContextEntityNode && nodesToProcess[0].ChildContainer.ChildEntityNodes.Count == 1) { nodesToProcess = nodesToProcess[0].ChildContainer.ChildEntityNodes; } // Find the child tree node if (nodesToProcess.Count > 1) { throw new Exception("Cross-join in report calculations are unsupported."); } var aggregateQueryNode = new AggregateEntity( ); context.ParentNodeStack.Push(aggregateQueryNode); SQ.Entity childNode; if (nodesToProcess.Count == 0) { childNode = new SingleRowNode( ); } else { childNode = nodesToProcess.Single( ).BuildQueryNode(context, false); } // Move child node to the right place (it will try to add to RelatedEntities, but we don't want it there) aggregateQueryNode.RelatedEntities.Clear( ); aggregateQueryNode.GroupedEntity = childNode; context.ParentNodeStack.Pop( ); // Register the aggregate context.ParentNode.RelatedEntities.Add(aggregateQueryNode); return(aggregateQueryNode); }