private int GetRelationshipCount()
    {
        int RelationshipNameID = RelationshipNameInfoProvider.GetRelationshipNameInfo(RelationshipName).RelationshipNameId;

        if (AllowSwitchSides)
        {
            return(RelationshipInfoProvider.GetRelationships()
                   .WhereEquals("RelationshipNameID", RelationshipNameID)
                   .Where(string.Format("(LeftNodeID = {0} or RightNodeID = {0})", CurrentNodeID))
                   .Count);
        }
        else
        {
            return(RelationshipInfoProvider.GetRelationships()
                   .WhereEquals("RelationshipNameID", RelationshipNameID)
                   .WhereEquals(DirectionMode == "LeftNode" ? "LeftNodeID" : "RightNodeID", CurrentNodeID)
                   .Count);
        }
    }
        private List <object> GetRelationshipElements(TreeNode node)
        {
            var query = new DataQuery();

            var nodeRelationshipsQuery = RelationshipInfoProvider.GetRelationships()
                                         .WhereEquals("LeftNodeID", node.NodeID);

            // Get all the relationships for the document and also empty records for every existing relationships that the document is not using to send a complete set of relationship elements
            var allRelationshipsQuery = query
                                        .From(
                @"
(" + query.IncludeDataParameters(nodeRelationshipsQuery.Parameters, nodeRelationshipsQuery.QueryText) + @") R
FULL OUTER JOIN CMS_RelationshipNameSite RNS ON R.RelationshipNameID = RNS.RelationshipNameID
LEFT JOIN CMS_RelationshipName RN ON RNS.RelationshipNameID = RN.RelationshipNameID
LEFT JOIN CMS_Tree T ON R.RightNodeID = T.NodeID
"
                )
                                        .Columns("NodeGUID", "RelationshipGUID")
                                        .WhereEqualsOrNull("RelationshipNameIsAdHoc", false)
                                        .WhereEquals("RNS.SiteID", node.NodeSiteID)
                                        .OrderBy("RelationshipOrder");

            var relationshipElements = allRelationshipsQuery
                                       .Result
                                       .Tables[0]
                                       .AsEnumerable()
                                       .GroupBy(row => (Guid)row["RelationshipGUID"])
                                       .Select(group => new {
                element = new
                {
                    external_id = ContentTypeSync.GetFieldExternalId(ContentTypeSync.RELATED_PAGES_GUID, group.Key)
                },
                value = (object)group
                        .Where(row => row["NodeGUID"] != DBNull.Value)
                        .Select(row => new { external_id = GetPageExternalId((Guid)row["NodeGUID"]) })
                        .ToList()
            })
                                       .Cast <object>()
                                       .ToList();

            return(relationshipElements);
        }
        private IList <Guid> GetRelatedNodeGuids(TreeNode node, FormFieldInfo relationshipsField)
        {
            var relationshipName     = RelationshipNameInfoProvider.GetAdHocRelationshipNameCodeName(node.ClassName, relationshipsField);
            var relationshipNameInfo = RelationshipNameInfoProvider.GetRelationshipNameInfo(relationshipName);

            if (relationshipNameInfo == null)
            {
                return(new List <Guid>());
            }

            var guids = RelationshipInfoProvider.GetRelationships()
                        .Columns("NodeGUID")
                        .Source(
                s => s.LeftJoin(new QuerySourceTable("CMS_Tree"), "RightNodeID", "NodeID")
                )
                        .WhereEquals("LeftNodeID", node.NodeID)
                        .WhereEquals("RelationshipID", relationshipNameInfo.RelationshipNameId)
                        .OrderBy("RelationshipOrder")
                        .GetListResult <Guid>();

            return(guids);
        }
 private int GetRelationshipCount()
 {
     return(RelationshipInfoProvider.GetRelationships()
            .WhereEquals("RelationshipNameID", GetRelationshipNameId())
            .WhereEquals("LeftNodeID", TreeNode.NodeID).Count);
 }
 private int GetRelationshipCount()
 {
     return RelationshipInfoProvider.GetRelationships().WhereEquals("RelationshipNameID", GetRelationshipNameId()).Count();
 }