【发布时间】:2012-03-29 02:30:12
【问题描述】:
我不熟悉使用 RavenDB 并尝试让索引在一个简单的 MVC3 应用程序中工作,该应用程序允许用户输入地理位置。我有两个模型,一个 UserModel 和一个 LocationModel。 LocationModel 在保存时存储 UserId,我正在尝试在此创建索引。
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();
}
它返回以下错误
找不到名为:Locations_ByUser 的索引
我想知道是否有其他人以前遇到过这种情况并可以为我指明正确的方向。提前致谢。
【问题讨论】:
标签: .net asp.net-mvc-3 ravendb indexing