2
我是新来的使用RavenDB并试图让索引工作在一个简单的MVC3应用程序,它允许用户输入地理位置。我有两个模型,一个UserModel和一个LocationModel。 LocationModel在保存时存储UserId,我试图在此上创建一个索引。RavenDB索引错误“找不到索引”
public class Locations_ByUser : AbstractIndexCreationTask<LocationModel>
{
public Locations_ByUser()
{
Map = locations => from location in locations
select new { location.UserId };
}
}
我用下面的代码注册指数
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
//ADD THE MODEL BINDER FOR LIST TO STRING
ModelBinders.Binders.Add(typeof(TestAPI.Models.LocationModel), new TestAPI.Classes.LocationModelBinder());
//INIT THE STORE, DO ONCE PER APP START
TestAPI.Classes.DataDocumentStore.Initialize();
//SET THE INDEXES
IndexCreation.CreateIndexes(typeof(Locations_ByUser).Assembly, TestAPI.Classes.DataDocumentStore.Instance);
}
然而,当我试图从MVC应用程序
[HttpGet]
public ActionResult Index()
{
var result = this.DocumentSession.Query<LocationModel>("Locations_ByUser").ToList();
foreach (var userid in result)
{
Console.Out.WriteLine(userid);
}
return View();
}
它返回以下错误调用索引
找不到名为的索引:Locat ions_ByUser
我想知道是否有其他人之前遇到过这种情况,并可以指出我在正确的方向。提前致谢。
你是真棒!你为我解决了两个问题。我无法弄清楚如何让Raven Studio加载嵌入式,并且由于这篇文章(以及让我的索引起作用)我追踪了它。我一定错过了文档中的命名约定。你碰巧知道我在哪里可以找到它? – jamesamuir 2012-03-29 03:20:44
我不认为在文档中提到了索引命名,我认为它是在版本4xx期间进行的更改。不完全确定。我快速查看并找不到它。 – Phill 2012-03-29 03:28:59