Rock.Model.ExceptionLogService.GetByParentId C# (CSharp) Method

GetByParentId() public method

Gets a collection of Rock.Model.ExceptionLog entities by the Id of their Parent exceptionId. Under most instances, only one child Rock.Model.ExceptionLog entity will be returned in the collection.
public GetByParentId ( int parentId ) : IQueryable
parentId int An containing the Id of the parent ExceptionLog entity to search by.
return IQueryable
        public IQueryable<ExceptionLog> GetByParentId( int? parentId )
        {
            return Queryable().Where( t => ( t.ParentId == parentId || ( parentId == null && t.ParentId == null ) ) );
        }

Usage Example

        /// <summary>
        /// Gets the related exception logs
        /// </summary>
        /// <param name="baseException">The base exception.</param>
        /// <returns>List of Exception Detail Summary objects</returns>
        private List<ExceptionLog> GetExceptionLogs( ExceptionLog baseException )
        {
            List<ExceptionLog> exceptionList = new List<ExceptionLog>();
            ExceptionLogService svc = new ExceptionLogService( new RockContext() );

            //load the base exception
            exceptionList.Add( baseException );

            //get the parentID
            int? parentId = baseException.ParentId;

            //loop through exception hierarchy (parent, grandparent, etc)
            while ( parentId != null && parentId > 0 )
            {
                var exception = svc.Get( (int)parentId );

                if ( exception != null )
                {
                    exceptionList.Add( exception );
                }

                parentId = exception.ParentId;
            }

            //get inner exceptions
            if ( baseException.HasInnerException != null &&  (bool)baseException.HasInnerException )
            {
                exceptionList.AddRange( svc.GetByParentId( baseException.Id ) );
            }

            return exceptionList;
        }