Question

I have written a code for index creation but when i run the application and try to call it then give a error of 'There is no index named'. My code is as follow :

I have created a class for index creation like :

 public class TicketsByPaymentTotal : AbstractIndexCreationTask<Tickets,TicketTotal>
    {
        public TicketsByPaymentTotal()
        {
            Map = docs => from doc in docs
                          select new
                          {
                              TicketId = doc.TicketData.ID,
                              TicketTotalVal = doc.TicketData.PaymentTotal,
                              TotalVal = doc.TicketData.Total
                          };
            Reduce = results => from result in results
                                group result by result.TicketId
                                    into g
                                    select new
                                    {
                                        TicketId = g.Key,
                                        TicketTotalVal = g.Sum(x => x.TicketTotalVal),
                                        TotalVal = g.Sum(x => x.TotalVal)
                                    };
        }
    } 

and i am creating index in global.asax file like :

public class MvcApplication : System.Web.HttpApplication
    {
        public IDocumentSession DocSession;
        //DocumentStore store = new DocumentStore{ConnectionStringName="RavenDB2",DefaultDatabase="Dinerware"};

        protected void Application_Start()
        {
            //AreaRegistration.RegisterAllAreas();


            DataDocumentStore.Initialize();
            DocSession = DataDocumentStore.Instance.OpenSession("Dinerware");
            RegisterRoutes(RouteTable.Routes);
            //store.Initialize();
            HandlerConfig.RegisterHandlers(GlobalConfiguration.Configuration.MessageHandlers);
            IndexCreation.CreateIndexes(typeof(TicketsByPaymentTotal).Assembly,DocSession.Advanced.DocumentStore);
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute("Default",
                "{controller}/{action}/{id}",
                new { controller="Home",action="Index",id=""});
        }
    }

How to solve this issue.

Thanks.

Regards,
sandy

Was it helpful?

Solution

You are creating the index in the system database, even though you are using a named instance called "Dinnerware".

  • If you want to use a named database, pass it in the DefaultDatabase parameter when you create the document store instance.

  • Don't pass the name when you are opening the session. That should be reserved for when you have multi-database needs.

  • You should just pass your document store instance into the CreateIndexes method directly, rather than pulling it out of session.

  • Don't open a session and assign it to a property. Sessions are meant to be short lived, and must be disposed. Only the document store should be long lived on a single instance. Usually, sessions are created in a using statement. In a web app, a new session should be created for each and every web request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top