Raven.Database.DocumentDatabase.PutIndex C# (CSharp) Method

PutIndex() public method

public PutIndex ( string name, Raven.Database.Indexing.IndexDefinition definition ) : string
name string
definition Raven.Database.Indexing.IndexDefinition
return string
		public string PutIndex(string name, IndexDefinition definition)
		{
			definition.Name = name = IndexDefinitionStorage.FixupIndexName(name);
			definition.RemoveDefaultValues();
			switch (IndexDefinitionStorage.FindIndexCreationOptions(definition))
			{
				case IndexCreationOptions.Noop:
					return name;
				case IndexCreationOptions.Update:
					// ensure that the code can compile
					new DynamicViewCompiler(name, definition, Extensions, IndexDefinitionStorage.IndexDefinitionsPath, Configuration).GenerateInstance();
					DeleteIndex(name);
					break;
			}
			IndexDefinitionStorage.AddIndex(definition);
			IndexStorage.CreateIndexImplementation(definition);
		    TransactionalStorage.Batch(actions =>
		    {
		        actions.Indexing.AddIndex(name, definition.IsMapReduce);
		        workContext.ShouldNotifyAboutWork();
		    });
			return name;
		}

Usage Example

		public QueryingOnStaleIndexes()
		{
			db = new DocumentDatabase(new RavenConfiguration { DataDirectory = "raven.db.test.esent", RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true });
			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
		

		}
All Usage Examples Of Raven.Database.DocumentDatabase::PutIndex