/// <summary> /// Gets the expression. /// </summary> /// <param name="context">The context.</param> /// <param name="entityIdProperty">The entity identifier property.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override System.Linq.Expressions.Expression GetExpression(Rock.Data.RockContext context, System.Linq.Expressions.MemberExpression entityIdProperty, string selection) { var attributeValueService = new AttributeValueService(context); var roomReservationGroupAttGuid = ZoomGuid.Attribute.ROOM_RESERVATION_GROUP_ATTRIBUTE.AsGuid(); var reservationLocationEntityTypeId = new EntityTypeService(context).GetNoTracking(com.bemaservices.RoomManagement.SystemGuid.EntityType.RESERVATION_LOCATION.AsGuid()).Id; var resGroupAttValues = attributeValueService.Queryable() .Where(x => x.Attribute.Guid == roomReservationGroupAttGuid) .Select(x => new { EntityId = x.EntityId, Value = x.Value }); var groupQuery = new GroupService(context).Queryable() .Select(g => new { GuidString = g.Guid.ToString(), GroupName = g.Name + " (" + g.Id.ToString() + ")" }); var reservationQuery = new ReservationService(context).Queryable() .Select(r => new { r.Id }); var reservationlocationQuery = new ReservationLocationService(context).Queryable() .Select(rl => new { rl.Id, rl.ReservationId }); var occurrenceService = new RoomOccurrenceService(context); var resultQuery = occurrenceService.Queryable("ReservationLocation") .Select(ro => groupQuery.FirstOrDefault(g => resGroupAttValues.FirstOrDefault(v => reservationQuery.FirstOrDefault(r => reservationlocationQuery.FirstOrDefault(rl => ro.EntityTypeId == reservationLocationEntityTypeId && rl.Id == ro.EntityId).ReservationId == r.Id).Id == v.EntityId).Value.Contains(g.GuidString)).GroupName); return(SelectExpressionExtractor.Extract(resultQuery, entityIdProperty, "ro")); }