Exemplo n.º 1
0
        /// <summary>
        /// Получить информацию об индексах
        /// </summary>
        /// <param name="storageIndexItemInfoCollection">Информация об индексах из хранилища</param>
        /// <param name="tableInfo">Информация о таблице</param>
        /// <returns>Информацию об индексах</returns>
        private List<IndexInfo> GetStorageIndexInfo(IEnumerable<StorageIndexItem> storageIndexItemInfoCollection, TableInfo tableInfo)
        {
            var indexes = new List<IndexInfo>();

            //группируем по таблицам
            List<StorageIndexItem> tableIndexGroupInfo = storageIndexItemInfoCollection.Where(i => i.TableName == tableInfo.Name).ToList();

            //группируем по именам индексов
            var indexNameGroups = tableIndexGroupInfo.GroupBy(i => i.IndexName).ToList();

            foreach (var indexNameGroup in indexNameGroups)
            {
                var isClustered = false;
                var isUnique = false;

                var entityIndexInfo = new IndexInfo() { Name = indexNameGroup.Key, TableInfo = tableInfo };

                var indexMemberItems = indexNameGroup.Where(i => i.IsIncludedColumn == false).ToList();
                var indexIncludeItems = indexNameGroup.Where(i => i.IsIncludedColumn == true).ToList();

                indexMemberItems.Sort(CompareStorageIndexItemOrder);
                indexIncludeItems.Sort(CompareStorageIndexItemOrder);

                int memberColumnOrder = 0;
                int includeColumnOrder = 0;
                foreach (var indexMemberItem in indexMemberItems)
                {
                    isClustered = indexMemberItem.IndexType.Equals("CLUSTERED");
                    isUnique = indexMemberItem.IsUnique;

                    var indexMemberInfo = new IndexMemberInfo()
                    {
                        ColumnInfo = new ColumnInfo(tableInfo, indexMemberItem.ColumnName),
                        IndexName = indexMemberItem.IndexName,
                        ColumnOrder = memberColumnOrder,
                        SortDirection = indexMemberItem.IsDescending == true ? SortDirection.Desc : SortDirection.Asc
                    };
                    entityIndexInfo.IndexMemberInfoCollection.Add(indexMemberInfo);

                    memberColumnOrder += 1;
                }

                foreach (var indexIncludeItem in indexIncludeItems)
                {
                    isClustered = indexIncludeItem.IndexType.Equals("CLUSTERED");
                    isUnique = indexIncludeItem.IsUnique;

                    var indexMemberInfo = new IndexIncludeInfo()
                    {
                        ColumnInfo = new ColumnInfo(tableInfo, indexIncludeItem.ColumnName),
                        IndexName = indexIncludeItem.IndexName,
                        ColumnOrder = includeColumnOrder,
                    };
                    entityIndexInfo.IndexIncludeInfoCollection.Add(indexMemberInfo);

                    includeColumnOrder += 1;
                }
                entityIndexInfo.IsClustered = isClustered;
                entityIndexInfo.IsUnique = isUnique;

                indexes.Add(entityIndexInfo);
            }

            return indexes;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Получить информацию об индексах
        /// </summary>
        /// <param name="storageIndexItemInfoCollection">Информация об индексах из хранилища</param>
        /// <param name="tableInfo">Информация о таблице</param>
        /// <returns>Информацию об индексах</returns>
        private List <IndexInfo> GetStorageIndexInfo(IEnumerable <StorageIndexItem> storageIndexItemInfoCollection, TableInfo tableInfo)
        {
            var indexes = new List <IndexInfo>();

            //группируем по таблицам
            List <StorageIndexItem> tableIndexGroupInfo = storageIndexItemInfoCollection.Where(i => i.TableName == tableInfo.Name).ToList();

            //группируем по именам индексов
            var indexNameGroups = tableIndexGroupInfo.GroupBy(i => i.IndexName).ToList();

            foreach (var indexNameGroup in indexNameGroups)
            {
                var isClustered = false;
                var isUnique    = false;

                var entityIndexInfo = new IndexInfo()
                {
                    Name = indexNameGroup.Key, TableInfo = tableInfo
                };

                var indexMemberItems  = indexNameGroup.Where(i => i.IsIncludedColumn == false).ToList();
                var indexIncludeItems = indexNameGroup.Where(i => i.IsIncludedColumn == true).ToList();

                indexMemberItems.Sort(CompareStorageIndexItemOrder);
                indexIncludeItems.Sort(CompareStorageIndexItemOrder);

                int memberColumnOrder  = 0;
                int includeColumnOrder = 0;
                foreach (var indexMemberItem in indexMemberItems)
                {
                    isClustered = indexMemberItem.IndexType.Equals("CLUSTERED");
                    isUnique    = indexMemberItem.IsUnique;

                    var indexMemberInfo = new IndexMemberInfo()
                    {
                        ColumnInfo    = new ColumnInfo(tableInfo, indexMemberItem.ColumnName),
                        IndexName     = indexMemberItem.IndexName,
                        ColumnOrder   = memberColumnOrder,
                        SortDirection = indexMemberItem.IsDescending == true ? SortDirection.Desc : SortDirection.Asc
                    };
                    entityIndexInfo.IndexMemberInfoCollection.Add(indexMemberInfo);

                    memberColumnOrder += 1;
                }

                foreach (var indexIncludeItem in indexIncludeItems)
                {
                    isClustered = indexIncludeItem.IndexType.Equals("CLUSTERED");
                    isUnique    = indexIncludeItem.IsUnique;

                    var indexMemberInfo = new IndexIncludeInfo()
                    {
                        ColumnInfo  = new ColumnInfo(tableInfo, indexIncludeItem.ColumnName),
                        IndexName   = indexIncludeItem.IndexName,
                        ColumnOrder = includeColumnOrder,
                    };
                    entityIndexInfo.IndexIncludeInfoCollection.Add(indexMemberInfo);

                    includeColumnOrder += 1;
                }
                entityIndexInfo.IsClustered = isClustered;
                entityIndexInfo.IsUnique    = isUnique;

                indexes.Add(entityIndexInfo);
            }

            return(indexes);
        }