public IQueryable <ContentChannelItem> ContentChannelItemsByAttributeValue(int campusId) { RockContext rockContext = new RockContext(); string campusGuid = new CampusService(rockContext).Get(campusId).Guid.ToString(); // Get the Id of the Rock.Model.ContentChannelItem Entity. int contentChannelItemEntityTypeId = EntityTypeCache.Get("Rock.Model.ContentChannelItem").Id; // Get the Field Type (Attribute Type) Id of the Data View Field Type. int fieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.CAMPUSES.AsGuid()).Id; // Get the list of attributes that are of the Rock.Model.ContentChannelItem entity type // and that are of the Campus field type. List <int> campusAttributeIdList = new AttributeService(rockContext) .GetByEntityTypeId(contentChannelItemEntityTypeId) .Where(item => item.FieldTypeId == fieldTypeId) .Select(a => a.Id) .ToList(); List <string> campusAttributeIdKeyList = new AttributeService(rockContext) .GetByEntityTypeId(contentChannelItemEntityTypeId) .Where(item => item.FieldTypeId == fieldTypeId) .Select(a => a.Key) .ToList(); var avsWithCampus = new AttributeValueService(rockContext).Queryable() .Where(a => campusAttributeIdList.Contains(a.AttributeId)) .Where(a => a.Attribute.EntityTypeId == contentChannelItemEntityTypeId) .Where(a => a.Value.Contains(campusGuid)) .Select(a => a.EntityId); // I want a list of content channel items whose ids match up to attribute values that represent entity ids IQueryable <ContentChannelItem> contentChannelItemList = new ContentChannelItemService(rockContext) .Queryable() .AsNoTracking() .Where(c => avsWithCampus.Contains(c.Id) || c.Attributes.Keys.Contains(campusAttributeIdKeyList.FirstOrDefault())); // Return this list return(contentChannelItemList); }