2
我需要的是簡單地檢索存儲在產品類別列表:如何創建具有鮮明操作的指標。 RavenDB
Products.Select(x => x.Category).Distinct().OrderBy(x => x);
當調用這個RavenDB
說我應該使用索引反而導致計算的查詢過程中是不允許的。
我讀了一些關於指標,但仍無法弄清楚howcome我創建一個索引?
我已經試過到目前爲止:
初始化
public class DataAccessModule : NinjectModule {
public override void Load() {
Bind<IDocumentStore>().ToMethod(
context => {
var documentStore = new EmbeddableDocumentStore {
DataDirectory = @"~/App_Data/database",
UseEmbeddedHttpServer = true,
DefaultDatabase = "SampleStore"
};
var store = documentStore.Initialize();
IndexCreation.CreateIndexes(typeof(CategoriesIndex).Assembly, store);
return store;
}
).InSingletonScope();
Bind<IDocumentSession>().ToMethod(context =>
context.Kernel.Get<IDocumentStore>().OpenSession()
).InRequestScope();
}
}
指數定義
public class CategoriesIndex : AbstractIndexCreationTask<Product> {
public CategoriesIndex() {
Map = ct => ct.Select(x => x.Categories).Distinct().OrderBy(x => x);
}
}
但是,這是行不通的。 Howcome我定義它的正確方法?
謝謝!
有沒有必要創建一個索引呢? – MickJuice 2015-05-16 13:28:41