如何在RavenDB中以编程方式创建索引?
我试着效仿这个例子.
这是我的索引创建者:
public class MyIndex : Raven.Client.Indexes.AbstractIndexCreationTask<MyEntity>
{
public MyIndex()
{
Map = col => col.Select(c => new
{
code = c.Code,
len = c.Code.Length,
sub = c.Code.Substring(0, 1)
});
}
}
Run Code Online (Sandbox Code Playgroud)
以下是来电者:
var store = new Raven.Client.Document.DocumentStore
{
Url = "http://localhost:8080"
};
store.Initialize();
try
{
using (var session = store.OpenSession("MyDB"))
{
Raven.Client.Indexes.IndexCreation.CreateIndexes(
typeof(MyIndex).Assembly, store);
}
}
finally
{
store.Dispose();
}
Run Code Online (Sandbox Code Playgroud)
索引已创建但不在MyDB中,而是在系统数据库中.
如何在MyDB中创建索引?我创建索引的方式是否正确?
小智 5
试试这个:在商店对象中指定数据库名称
var store = new Raven.Client.Document.DocumentStore
{
Url = "http://localhost:8080",
DefaultDatabase = "MyDB"
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1200 次 |
| 最近记录: |