我正在尝试为多租户 ravendb 编写一个通用删除函数,用于集成测试该类是 -
public class RavenDeleteAll
{
private readonly IDocumentStore _store;
private readonly string _testDataBase;
public RavenDeleteAll(string testDataBase, IDocumentStore store)
{
_testDataBase = testDataBase;
_store = store;
}
public void Clear<T>(string indexName)
{
using (var session = _store.OpenSession(_testDataBase))
{
session.Advanced.DocumentStore.DatabaseCommands.DeleteIndex(indexName);
session.Advanced.DocumentStore.DatabaseCommands.PutIndex(indexName, new IndexDefinitionBuilder<T>
{
Map = documents => documents.Select(entity => new { })
});
var indexDefinition = session.Advanced.DocumentStore.DatabaseCommands.GetIndex(indexName);
session.Advanced.LuceneQuery<T>(indexName)
.WaitForNonStaleResultsAsOfNow()
.Take(0)
.ToList();
session.Advanced.DatabaseCommands.DeleteByIndex(indexName, new IndexQuery());
}
}
}
请注意,在代码中,我尝试在 putindex 调用后读回索引以进行完整性检查。但是当我执行索引时,它会抛出一个无效操作异常,说明 /indexes/UTO 不存在?
同样从管理控制台我可以清楚地看到索引 -
我不做什么?另外索引是在默认数据库下创建的,而不是实际的数据库名称?