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

Get() public method

Returns an Rock.Model.Attribute by Rock.Model.EntityType, EntityQualifierColumn, EntityQualiferValue and Key name.
public Get ( int entityTypeId, string entityQualifierColumn, string entityQualifierValue, string key ) : Attribute
entityTypeId int A that represents the EntityTypeId of the to search by.
entityQualifierColumn string A that represents the name of the EntityQualifierColumn to search by.
entityQualifierValue string A that represents the EntityQualifierValue to search by.
key string A representing the key name of the attribute to search by.
return System.Attribute
        public Attribute Get( int? entityTypeId, string entityQualifierColumn, string entityQualifierValue, string key )
        {
            var query = Get(entityTypeId, entityQualifierColumn, entityQualifierValue);
            return query.Where( t => t.Key == key ).FirstOrDefault();
        }

Same methods

AttributeService::Get ( int entityTypeId, string entityQualifierColumn, string entityQualifierValue ) : IQueryable

Usage Example

Example #1
0
        /// <summary>
        /// Returns Attribute object from cache.  If attribute does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id">The id of the Attribute to read</param>
        /// <returns></returns>
        public static AttributeCache Read(int id)
        {
            string cacheKey = AttributeCache.CacheKey(id);

            ObjectCache    cache     = MemoryCache.Default;
            AttributeCache attribute = cache[cacheKey] as AttributeCache;

            if (attribute != null)
            {
                return(attribute);
            }
            else
            {
                var attributeService = new Rock.Model.AttributeService();
                var attributeModel   = attributeService.Get(id);
                if (attributeModel != null)
                {
                    attribute = new AttributeCache(attributeModel);
                    cache.Set(cacheKey, attribute, new CacheItemPolicy());
                    return(attribute);
                }
                else
                {
                    return(null);
                }
            }
        }
All Usage Examples Of Rock.Model.AttributeService::Get