예제 #1
0
        /// <summary>
        /// Executes the index creation against the specified document database using the specified conventions
        /// </summary>
        public virtual void Execute(IDatabaseCommands databaseCommands, DocumentConvention documentConvention)
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

#if !DNXCORE50
            if (documentConvention.PrettifyGeneratedLinqExpressions)
            {
                var serverDef = databaseCommands.GetIndex(IndexName);
                if (serverDef != null && CurrentOrLegacyIndexDefinitionEquals(documentConvention, serverDef, indexDefinition))
                {
                    AfterExecute(databaseCommands, documentConvention);
                    return;
                }
            }
#endif

            // This code take advantage on the fact that RavenDB will turn an index PUT
            // to a noop of the index already exists and the stored definition matches
            // the new definition.
            databaseCommands.PutIndex(IndexName, indexDefinition, true);

            if (Priority != null)
            {
                databaseCommands.SetIndexPriority(IndexName, Priority.Value);
            }

            AfterExecute(databaseCommands, documentConvention);
        }
예제 #2
0
        /// <summary>
        /// Executes the index creation against the specified document database using the specified conventions
        /// </summary>
        public virtual void Execute(IDatabaseCommands databaseCommands, DocumentConvention documentConvention)
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();

            if (documentConvention.PrettifyGeneratedLinqExpressions)
            {
                var serverDef = databaseCommands.GetIndex(IndexName);
                if (serverDef != null && CurrentOrLegacyIndexDefinitionEquals(documentConvention, serverDef, indexDefinition))
                {
                    return;
                }
            }

            // This code take advantage on the fact that RavenDB will turn an index PUT
            // to a noop of the index already exists and the stored definition matches
            // the new definition.
            databaseCommands.PutIndex(IndexName, indexDefinition, true);

            if (Priority != null)
            {
                databaseCommands.SetIndexPriority(IndexName, Priority.Value);
            }

            if (Conventions.IndexAndTransformerReplicationMode.HasFlag(IndexAndTransformerReplicationMode.Indexes))
            {
                ReplicateIndexesIfNeeded(databaseCommands);
            }
        }