MVC4+RavenDb Avoiding Quick Start Pitfalls


Coming from a SharePoint (library/list/caml) or SQL Server table point of view you typically construct end-user content based on normalized, or semi-normalized data formed from tables/libraries/lists of rows and columns. This is wonderful for adhoc reporting or creating new content pages from queries (or other middle tier magic programming). Once that data is “formed” you can display it directly or add to business objects having the “same shape” as the data for further processing.

A few words on this approach – data coming from a SQL store will be processed based on a query that defines its ultimate purpose. This is fine for queries that must change often, such as a reporting application, and you have no substantial processing time constraints. However, for OLTP and other system elements that tend to use the same (unchanging) queries against raw data the adhoc nature of these queries adds a layer of unnecessary processing. This processing would be avoided if the data was already stored in the same “shape” as the original query. To say this another way, if the database preserved the hierarchical relationship between data elements and stored these elements together as a single document, blob, or class you could simply choose the proper index and pull the data out in a single “highly atomic” transaction. The document would naturally map into business logic objects (or better yet – be hydrated into the actual object). This is also referred to as the NoSQL approach.

RavenDb is a database that captures data as documents. A NoSQL document database. The documents are formed by declaring classes in code and persisting those classes in its database. The concept has been around for a while – the key distinctions here are that objects are persisted using JSON syntax and directly executable by JavaScript (more or less). This means a modern web application can very easily take advantage of this style of storage and offers the programmer a virtually no impedance mismatch between the client and server – its easy to program.

MVC is a perfect technology playground for testing the waters with RavenDb. I decided to construct a sample application using MVC 4 (currently in beta). So this post is a simple quick start that emphasizes a couple of tips… this point install MVC 4 into Visual Studio 2010, Create an MVC 4 Project.

Tip 1: In NuGet (GUI version shown below) – search online using term, “RavenDb”. If you are on a development server you should choose the first option for these reasons:

  1. This is a stable version of RavenDb for use with MVC4 (as far as I can tell so far). Later (unstable) versions of RavenDb throw JSON exceptions (in my experience). I had to uninstall the later versions and add this one into my project. Lesson learned.
  2. Unless you’re building a true embedded version of your application – which is certainly possible – you would likely use a hosting providers RavenDb database instance provided via a unique port number (in my case its http://dev:8080 on my development server)

Tip 2:

If you find yourself installing from the NuGet command line in Visual Studio 2010 using this command Install-Package RavenDB -Pre  you probably installed some ill-tempered version. To fix this simply issue this statement Uninstall-Package RavenDb –RemoveDependencies 

Now, go back into the GUI package manager and click install as shown in this image (the first package on the list). You are ready to configure RavebDb


Tip 2: Be sure you have an instance of the RavenDb running on its default port within your development server. This operation is completely independent of your project. To install a running instance on your development database follow these steps:

  1. Locate the downloaded package from your solutions pagages folder. I found mine located in the directory [solution name]\packages\RavenDB.1.0.701 (your version may vary)
  2. Navigate to the \server folder and execute this command
  3. Raven.Server.exe /install see this link

Verify that the service instance is started in your Windows Service administration panel


In your browser, navigate to http://localhost:8080 and see the administrative screen is functional. Also, install Silverlight (as that is used by RavenDb for the page) 


You are ready to “rock-and-roll”!

Tip 3: Back to MVC, the following link provides the essential information to “rewire” your MVC project for use with RavenDb

Once you have the MVC Controllers inheriting from the RavenDB base controller you can wire up some views for testing.

My next RavenDb post will be on working with JavaScript and Views

That’s it for now – Cheers!

PS: I will resume my tutorial on building SharePoint 2010 Service Applications soon… 


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s