RavenDB embedabble

I have made an application with RavenDB embeddable.

The good part is that is embeddable and easy to work with – at least, at start.

What I have learned:

  • If you forgot to use using, then RavenDB will throw an exception complaining about multiple sessions. Code:
 using (var session = instanceDefault.OpenSession(DatabaseName()))
{

//code
}

 

  • If you use multiple instance of the same EmbeddableDocumentStore , even on different default databases , then will complain about “temp path already used by another database instance “ . And the generics do NOT share the same instance of a static variable. And when you dispose a static singleton instance ? At the final of the application ( do not forget , otherwise you may have again “temp path already used by another database instance ” !)

 

  • The most simple index for new databases is RavenDocumentsByEntityName . Code:
//static EmbeddableDocumentStore instanceDefault;
var dbc = instanceDefault.DatabaseCommands.ForDatabase(DatabaseName());
                var defIndex = new RavenDocumentsByEntityName();
                
                defIndex.Execute(dbc,new DocumentConvention()
                {
                    DefaultUseOptimisticConcurrency = true                    
                    
                } );

 

  • If you create an index, create in the Database that needs. Otherwise if will complain when you get the data.  ( see previous code)

 

  • To manage data / databases , there is RavenDB Management Studio – a fancy name for an application that you can access ( by default ) at http://localhost:8080 . Code:
            instanceDefault = new EmbeddableDocumentStore();
//I have put this in app.config/web.config
            //instanceDefault.Configuration.Settings.Add("Raven/MaxSecondsForTaskToWaitForDatabaseToLoad", "60");
/*
<connectionStrings>
		<add name="RavenDB" connectionString="DataDir = ~\App_Data\Database"/>
	</connectionStrings>
   <appSettings>
	<add key="Raven/MaxSecondsForTaskToWaitForDatabaseToLoad" value="60"/>
*/
            instanceDefault.ConnectionStringName = "RavenDB";
            instanceDefault.Conventions.FindIdentityPropertyNameFromEntityName = (entity) => "ID";

            try
            {
                //To try in debug mode
                NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8080);
                instanceDefault.UseEmbeddedHttpServer = true;
                instanceDefault.Initialize();

            }
            catch (ReflectionTypeLoadException ex)
            {
                string message = "LoaderExceptions:";
                ex.LoaderExceptions.ForEach(it => message += it.Message + ";");
                throw new Exception(message, ex);
            }


 

( do not let this into Web Application if you want to deploy to a third party host)

 

  • Copy / paste database do not work. You must backup and restore data( preferably with RavenDB Management Studio )

 

  • RavenDB documentation is ok – however, embeddable database is not so represented very well

 

If you want to see a sample ( not very good, though) repository, I have created one at https://github.com/ignatandrei/RomaniaOpenData/blob/master/ROP/ROPInfrastructure/Repository.cs

Bottom line: I think that is good enough.