/// <summary>
        ///     Handles a custom join.
        /// </summary>
        /// <param name="customJoinNode"></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 RegisterCustomJoinNode(CustomJoinNode customJoinNode, SqlTable parentTable, SqlQuery sqlQuery)
        {
            string predicateScript = customJoinNode.JoinPredicateScript;

            if (predicateScript == null)
            {
                throw new Exception("No script was specified.");
            }
            if (customJoinNode.EntityTypeId == null)
            {
                throw new Exception("No type was specified.");
            }

            SqlTable childTable = ConstrainDefinitionType(null, customJoinNode.EntityTypeId, customJoinNode.ExactType, sqlQuery);

            if (childTable == null)
            {
                // Ensure primary table
                // primary may still be null in scenario where joined is 'all resource types', or if root type check is suppressed
                childTable = sqlQuery.CreateTable("dbo.Entity", "e");
                childTable.FilterByTenant = true;
                childTable.IdColumn       = "Id";
            }

            childTable.Parent = parentTable;
            parentTable.Children.Add(childTable);
            childTable.DependsOnOtherJoins = true;

            // Join condition gets stitched up later in ApplyScriptCustomJoinPredicates

            // Join hints
            JoinHint joinHint;

            if (customJoinNode.ResourceMustExist)
            {
                joinHint = JoinHint.Required;
            }
            else if (customJoinNode.ResourceNeedNotExist)
            {
                joinHint = JoinHint.DontConstrainParent;
            }
            else
            {
                joinHint = JoinHint.Unspecified;
            }
            childTable.JoinHint = joinHint;
            childTable.JoinNotConstrainedByParent = customJoinNode.ParentNeedNotExist;

            return(new EntityTables(childTable));
        }
Exemple #2
0
        /// <summary>
        /// Builds the custom join report node.
        /// </summary>
        /// <param name="reportNode">The report node.</param>
        /// <param name="context">The context.</param>
        /// <returns>DownCastResource.</returns>
        private static CustomJoinNode BuildCustomJoinReportNode(CustomJoinReportNode reportNode, FromEntityContext context)
        {
            CustomJoinNode customJoinNode = new CustomJoinNode
            {
                JoinPredicateScript  = reportNode.JoinPredicateCalculation,
                EntityTypeId         = reportNode.ResourceReportNodeType?.Id,
                ResourceMustExist    = reportNode.TargetMustExist ?? false,
                ResourceNeedNotExist = reportNode.TargetNeedNotExist ?? false,
                ParentNeedNotExist   = reportNode.ParentNeedNotExist ?? false,
                ExactType            = reportNode.ExactType ?? false
            };
            Guid nodeId;

            if (!context.ReportNodeMap.TryGetValue(reportNode.Id, out nodeId))
            {
                nodeId = Guid.NewGuid( );
                context.ReportNodeMap[reportNode.Id] = nodeId;
            }
            customJoinNode.NodeId   = nodeId;
            customJoinNode.EntityId = reportNode.Id;
            return(customJoinNode);
        }