RavenDB索引错误"无法找到名为"的索引

jam*_*uir 3 .net indexing ravendb asp.net-mvc-3

我是新手使用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 };

        }
    }
Run Code Online (Sandbox Code Playgroud)

我正在使用以下代码注册索引

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);
        }
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试从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();
        }
Run Code Online (Sandbox Code Playgroud)

它返回以下错误

找不到名为:Locations_ByUser的索引

我想知道是否有其他人之前遇到过这种情况并且可以指出我正确的方向.提前致谢.

Phi*_*ill 5

RavenDB中的索引实际上会在生成时命名为"Locations/ByUser".

如果你打开Raven Studio,你可以在索引下看到这个._被替换为/

此外,您不需要指定字符串值,您可以编写如下查询:

var result = this.DocumentSession.Query<LocationModel, Locations_ByUser>().ToList();
Run Code Online (Sandbox Code Playgroud)