Alw*_*wyn 8 c# indexing ravendb
如何检查索引是否存在? - 致电前:
IndexCreation.CreateIndexes(typeof(MyIndexClass).Assembly, documentStore);
Run Code Online (Sandbox Code Playgroud)
我看到的所有示例(包括示例项目中的示例)都在每次启动客户端时重新创建索引,这似乎不正确.
一般策略是什么?似乎有正常的CRUD操作,然后有管理命令,如上面的索引.人们只是创建一个控制台应用程序来执行管理员并与主应用程序分开部署/运行吗?
Mat*_*int 18
您不必检查是否存在.服务器将自动比较您发送的索引定义并检查它是否已存在.如果存在一个具有相同名称和定义的内容,那么它将保持不变.如果存在一个名称相同但定义已更改,则删除旧名称并创建新名称.
通常,在应用程序启动时,可以在同一个应用程序中创建索引.对于可能位于global.asax中的Web应用程序,以及控制台/桌面应用程序,它只是启动代码的第一部分.
但有时这是不可能的,例如,如果您有许多不同的数据库,就像多租户应用程序经常这样做.在这些情况下,您将在创建每个租户数据库时创建索引,并且在推出版本升级时可能需要更新或创建更多索引.
另外,我应该提一下,您可以通过几种不同的方式创建索引.
// scans the assembly for all indexes and creates them
IndexCreation.CreateIndexes(assembly, documentStore);
// scans a MEF catalog for all indexes and creates them
IndexCreation.CreateIndexes(catalog, documentStore);
// puts a single index the HARD way
documentStore.DatabaseCommands.PutIndex(...);
// puts a single index the easy way
documentStore.ExecuteIndex(new YourIndexCreationTask());
Run Code Online (Sandbox Code Playgroud)
还有其他一些,但你明白了.
而只是为了要彻底,如果你真的没有要检查索引所有脑干,你可以使用:
documentStore.DatabaseCommands.GetIndex("YourIndex") != null
Run Code Online (Sandbox Code Playgroud)
但这只会按名称检查,而不是按定义检查.你不需要它.
| 归档时间: |
|
| 查看次数: |
2013 次 |
| 最近记录: |