private void LoadTableMetaData() { // Try to load the partition meta data from the existing table (which contains a list of the partition keys in the table). _partitionMetaDataEntityWrapper = _tableMetaDataContext.Find(CtConstants.TableMetaDataPartitionKey, CtConstants.PartitionSchemasRowKey); // Set the default PartitionKey using the combination below in case there are more than one CloudTableContext objects // on the same table. _defaultIndexDefinitionName = $"DefaultIndex_ofType_{typeof(TDomainEntity).Name}"; if (_partitionMetaDataEntityWrapper != null) { /* This is going through and populating the local PartitionKeysInTable property with the list of keys retrieved * from the Azure table. * This also checks to see if there is a PartitionKey for the table meta data and the DefaultPartition * and adds that if there isn't*/ var metaDataPkIsInList = false; foreach (var partitionKeyString in _partitionMetaDataEntityWrapper.DomainObjectInstance.PartitionKeys) { if (partitionKeyString == CtConstants.TableMetaDataPartitionKey) { metaDataPkIsInList = true; } var isInList = false; foreach (var item in IndexNameKeysInTable) { if (item == partitionKeyString) { isInList = true; } } if (!isInList) { IndexNameKeysInTable.Add(partitionKeyString); } } if (!metaDataPkIsInList) { IndexNameKeysInTable.Add(CtConstants.TableMetaDataPartitionKey); } // The RowKey for the DefaultSchema is set by the given ID property of the TDomainEntity object DefaultIndex = CreateIndexDefinition(_defaultIndexDefinitionName) .DefineIndexCriteria(entity => true) .SetIndexedPropertyCriteria(entity => entity.GetType().Name); // Enables searching directly on the type. if (IndexDefinitions.All(indexDefinition => indexDefinition.IndexNameKey != DefaultIndex.IndexNameKey)) { AddIndexDefinition(DefaultIndex); } } else { /* Creates a new partition meta data entity and adds the appropriate default partitions and metadata partitions*/ _partitionMetaDataEntityWrapper = new TableEntityWrapper <PartitionMetaData>(CtConstants.TableMetaDataPartitionKey, CtConstants.PartitionSchemasRowKey); DefaultIndex = CreateIndexDefinition(_defaultIndexDefinitionName) .DefineIndexCriteria(entity => true) .SetIndexedPropertyCriteria(entity => entity.GetType().Name); // Enables searching directly on the type AddIndexDefinition(DefaultIndex); } }
/// <summary> /// Adds a single Index Definition to the current <see cref="TableContext{TDomainEntity}"/>. /// </summary> /// <param name="tableIndexDefinition"></param> public void AddIndexDefinition(TableIndexDefinition <TDomainEntity> tableIndexDefinition) { if (IndexDefinitions.Any(indexDef => indexDef.IndexNameKey == tableIndexDefinition.IndexNameKey)) { return; } IndexDefinitions.Add(tableIndexDefinition); }
/// <summary> /// Adds multiple Index Definitions types to the current <see cref="TableContext{TDomainEntity}"/>. /// </summary> /// <param name="indexDefinitions"></param> public void AddMultipleIndexDefinitions(List <TableIndexDefinition <TDomainEntity> > indexDefinitions) { foreach (var indexDefinition in indexDefinitions) { if (IndexDefinitions.Any(indexDef => indexDef.IndexNameKey == indexDefinition.IndexNameKey)) { continue; } IndexDefinitions.Add(indexDefinition); } }