Rock.Model.AttributeService.GetByEntityTypeId C# (CSharp) Method

GetByEntityTypeId() public method

Returns a queryable collection of Rock.Model.Attribute">Attributes by
public GetByEntityTypeId ( int entityTypeId ) : IQueryable
entityTypeId int A representing the EntityTypeId of the to search by.
return IQueryable
        public IQueryable<Attribute> GetByEntityTypeId( int? entityTypeId )
        {
            var query = Queryable();

            if ( entityTypeId.HasValue )
            {
                query = query.Where( t => t.EntityTypeId == entityTypeId );
            }
            else
            {
                query = query.Where( t => !t.EntityTypeId.HasValue );
            }

            return query.OrderBy( t => t.Order ).ThenBy( t => t.Name );
        }

Usage Example

Example #1
0
            /// <summary>
            /// Called after the save operation has been executed
            /// </summary>
            /// <remarks>
            /// This method is only called if <see cref="M:Rock.Data.EntitySaveHook`1.PreSave" /> returns
            /// without error.
            /// </remarks>
            protected override void PostSave()
            {
                if (this.State == EntityContextState.Deleted)
                {
                    var qualifierValue     = Entity.Id.ToString();
                    var rockContext        = ( RockContext )this.RockContext;
                    var attributeService   = new AttributeService(rockContext);
                    var existingAttributes = attributeService.GetByEntityTypeId(new ConnectionRequest().TypeId, true)
                                             .AsQueryable()
                                             .Where(a =>
                                                    a.EntityTypeQualifierColumn.Equals("ConnectionTypeId", StringComparison.OrdinalIgnoreCase) &&
                                                    a.EntityTypeQualifierValue.Equals(qualifierValue))
                                             .OrderBy(a => a.Order)
                                             .ThenBy(a => a.Name)
                                             .ToList();

                    foreach (var attr in existingAttributes)
                    {
                        attributeService.Delete(attr);
                        rockContext.SaveChanges();
                    }
                }

                base.PostSave();
            }
All Usage Examples Of Rock.Model.AttributeService::GetByEntityTypeId