コード例 #1
0
        /// <summary>
        /// Gets a list of GroupType Ids, including our own Id, that identifies the
        /// inheritence tree.
        /// </summary>
        /// <param name="groupTypeGuid">The parent group type Id to start from.</param>
        /// <returns>A list of GroupType Ids, including our own Id, that identifies the inheritence tree.</returns>
        public List <int> GetDescendantInheritedGroupTypeIds(int groupTypeId)
        {
            var rockContext = new RockContext();

            var groupTypeService = new GroupTypeService(rockContext);

            return(groupTypeService.ExecuteQuery(@"
				WITH CTE AS (
		            SELECT [Id],[InheritedGroupTypeId] FROM [GroupType] WHERE [Id] = {0}
		            UNION ALL
		            SELECT [a].[Id],[a].[InheritedGroupTypeId] FROM [GroupType] [a]
		            JOIN CTE acte ON acte.[Id] = [a].[InheritedGroupTypeId]
                 )
                SELECT *
                FROM [GroupType]
                WHERE [Id] IN ( SELECT [Id] FROM CTE )", groupTypeId)
                   .Select(t => t.Id)
                   .ToList());
        }