private IEnumerable <StoredPartialIndexFilterInfo> GetPartialIndexes()
        {
            if (!services.ProviderInfo.Supports(ProviderFeatures.PartialIndexes))
            {
                return(Enumerable.Empty <StoredPartialIndexFilterInfo>());
            }
            var metadata = context.Metadata;

            if (metadata == null)
            {
                return(Enumerable.Empty <StoredPartialIndexFilterInfo>());
            }
            var extensions = metadata.Extensions.Where(e => e.Name == WellKnown.PartialIndexDefinitionsExtensionName);
            var result     = new List <StoredPartialIndexFilterInfo>();

            foreach (var extension in extensions)
            {
                var items = StoredPartialIndexFilterInfoCollection.Deserialize(extension.Value).Items;
                if (items != null)
                {
                    result.AddRange(items);
                }
            }
            return(result);
        }
        private ExtensionMetadata GetPartialIndexes(Domain domain, IEnumerable <TypeInfo> types)
        {
            if (!domain.StorageProviderInfo.Supports(ProviderFeatures.PartialIndexes))
            {
                return(null);
            }
            var compiler = UpgradeContext.Services.IndexFilterCompiler;
            var handlers = domain.Handlers;
            var indexes  = types
                           .SelectMany(type => type.Indexes
                                       .Where(i => i.IsPartial && !i.IsVirtual && !i.IsAbstract)
                                       .Select(i => new { Type = type, Index = i }))
                           .Select(item => new StoredPartialIndexFilterInfo {
                Database = item.Type.MappingDatabase,
                Schema   = item.Type.MappingSchema,
                Table    = item.Type.MappingName,
                Name     = item.Index.MappingName,
                Filter   = compiler.Compile(handlers, item.Index)
            })
                           .ToArray();

            if (indexes.Length == 0)
            {
                return(null);
            }
            var items = new StoredPartialIndexFilterInfoCollection {
                Items = indexes
            };

            return(new ExtensionMetadata(WellKnown.PartialIndexDefinitionsExtensionName, items.Serialize()));
        }