private RelationData GetRelation(uint relationId)
 {
     if (!allRelations.ContainsKey(relationId))
     {
         using (var scope = new DatabaseScope(databaseName))
         {
             var          loadedRelation = relationsRepository.Get(relationId);
             RelationData relationData   = null;
             if (loadedRelation != null)
             {
                 relationData = new RelationData(loadedRelation);
             }
             allRelations.Add(relationId, relationData);
         }
     }
     return(allRelations[relationId]);
 }
 protected override void OnExecute()
 {
     using (var scope = new DatabaseScope(context.Database.Name))
     {
         var existingIndices = indicesRepository.GetAll();
         foreach (var i in existingIndices)
         {
             var relation           = relationsRepository.Get(i.RelationID);
             var relationData       = new RelationData(relation);
             var attributes         = new List <AttributeData>();
             var includedAttributes = new List <AttributeData>();
             foreach (var atrributeName in i.AttributesNames)
             {
                 var attribute = attributesRepository.Get(relation.ID, atrributeName);
                 var toAdd     = new AttributeData(relationData, attribute);
                 if (IsIncludedAttribute(i.CreateDefinition, attribute.Name))
                 {
                     includedAttributes.Add(toAdd);
                 }
                 else
                 {
                     attributes.Add(toAdd);
                 }
             }
             var existingIndexToAdd = new IndexDefinition(Convert(i.AccessMethod), relationData, attributes, includedAttributes);
             if (context.StatementsData.AllQueriesByRelation.TryGetValue(relation.ID, out var possibleQueriesForIndex))
             {
                 foreach (var statementQueryPair in possibleQueriesForIndex)
                 {
                     var normalizedStatementID = statementQueryPair.NormalizedStatementID;
                     var normalizedStatement   = context.StatementsData.All[normalizedStatementID].NormalizedStatement;
                     var query         = statementQueryPair.Query;
                     var extractedData = context.StatementsExtractedData.DataPerQuery[statementQueryPair];
                     if (IndexApplicability.IsIndexApplicableForQuery(extractedData, existingIndexToAdd))
                     {
                         context.IndicesDesignData.ExistingIndices.TryAddPossibleIndices(new[] { existingIndexToAdd }, normalizedStatement, query);
                     }
                 }
             }
         }
     }
 }